Johannes Schaub (litb) wrote: > Sebastian Redl wrote: > >> Author: cornedbee >> Date: Sun Jun 5 07:23:08 2011 >> New Revision: 132661 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=132661&view=rev >> Log: >> Expand on braced init list tests. >> > ... >> namespace objects { >> >> + template <int N> >> struct A { >> - A(); >> - A(int, double); >> - A(int, int); >> - A(std::initializer_list<int>); >> - >> - int operator[](A); >> + A() { static_assert(N == 0, ""); } >> + A(int, double) { static_assert(N == 1, ""); } >> + A(int, int) { static_assert(N == 2, ""); } >> + A(std::initializer_list<int>) { static_assert(N == 3, ""); } >> }; >> >> void initialization() { > ... >> + { A<0> a{}; } >> + { A<0> a = {}; } >> + { A<1> a{1, 1.0}; } >> + { A<1> a = {1, 1.0}; } >> + { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; } >> + { A<3> a = {1, 2, 3, 4, 5, 6, 7, 8}; } >> + { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; } >> + { A<3> a{1, 2}; } > > This looks incorrect to me. All constructs, except the first two (which > does value-initialization and use the first constructor), use the last > constructor (the initializer list constructor). >
What I didn't notice is that in the third and fourth case, the initialization of the parameter will use a narrowing conversion and hence the program will be ill-formed. But according to 13.3.3.1.5p2, all that is not considered during overload resolution. The existence of an implicit conversion sequence for double to int is enough to make the initializer list constructor viable and be chosen. The intent of this is described in section "{}-lists and narrowing" of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2640.pdf _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits