ARTICLE AD BOX
I have an aggregate class template with two element array inside:
template<typename T> struct A { T t[2]; };and I would like to initialize an object of this class using class template argument deduction (CTAD) from the type of the second element, so the first argument is braced-init-list having no type:
constexpr A a{ { {1}, 2.5 } }; static_assert( a.t[0] == 1. && a.t[1] == 2.5 );It indeed works in GCC, Clang and EDG, however the last two print the corresponding warnings
warning: braces around scalar initializer [-Wbraced-scalar-init] warning: extra braces are nonstandardClearly, removing the braces around 1 (as warnings suggest) fails the compilation everywhere.
And only MSVC rejects the program with the error:
<source>(5): error C2641: cannot deduce template arguments for 'A' <source>(5): note: 'A<double> A<double>(const double (&)[2])': cannot convert argument 1 from 'initializer list' to 'const double (&)[2]' ...And if the initialization of A is done using round brackets: constexpr A b( { {1}, 2.5 } ); then GCC (and not the others) changes its mind, starting showing long error:
<source>:9:29: error: class template argument deduction failed: <source>:9:29: error: no matching function for call to 'A(<brace-enclosed initializer list>)' <source>:9:29: note: there are 3 candidates ... <source>:2:8: note: candidate 3: 'A(T [2]) -> A<T> [with T = double]' <source>:2:8: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'double*Which implementation is correct here?
