[cfe-commits] r132661 - /cfe/trunk/test/SemaCXX/generalized-initializers.cpp

Johannes Schaub (litb) schaub.johannes at googlemail.com
Sun Jun 5 06:43:42 PDT 2011


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




More information about the cfe-commits mailing list