[cfe-commits] r159733 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/CodeGenCXX/const-init-cxx11.cpp test/CodeGenCXX/constructor-init.cpp test/SemaCXX/constant-expression-cxx11.cpp test/SemaCXX/cxx0x-initializer-constructor.cpp

Johannes Schaub schaub.johannes at googlemail.com
Sun Jul 8 11:34:03 PDT 2012


Am 08.07.2012 20:24, schrieb James Dennett:
> On Sun, Jul 8, 2012 at 6:41 AM, Johannes Schaub
> <schaub.johannes at googlemail.com> wrote:
>> Am 05.07.2012 10:39, schrieb Richard Smith:
>>> Author: rsmith
>>> Date: Thu Jul  5 03:39:21 2012
>>> New Revision: 159733
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=159733&view=rev
>>> Log:
>>> PR13273: When performing list-initialization with an empty initializer list,
>>> actually perform value initialization rather than trying to fake it with a call
>>> to the default constructor. Fixes various bugs related to the previously-missing
>>> zero-initialization in this case.
>>>
>> ...
>>> +namespace explicit_default {
>>> +  struct A {
>>> +    explicit A(); // expected-note{{here}}
>>> +  };
>>> +  A a {}; // ok
>>> +  // This is copy-list-initialization, and we choose an explicit constructor
>>> +  // (even though we do so via value-initialization), so the initialization is
>>> +  // ill-formed.
>>> +  A b = {}; // expected-error{{chosen constructor is explicit}}
>>> +}
>>> +
>>
>> Richard, I'm pretty sure that this is valid code. A value-initialization
>> doesn't respect "explicit". Are you assuming a C++ Standard defect here?
>
> The law governing this initially _seems_ to be "An explicit
> constructor constructs objects just like non-explicit constructors,
> but does so only where the direct-initialization syntax (8.5) or where
> casts (5.2.9, 5.4) are explicitly used."
>

I think that paragraph is only a summary and needs to refer to other 
paragraph that defines this in more details (which is why it contains 
cross references). In fact 8.5 and clause 13 precisely define when and 
when not converting constructors can and cannot be used.

They also define whether constructors are merely ignored or just forbidden.

     struct A {
       explicit A(int = 0);
       A(bool = true);
     };

     A a = {}; // valid or ambiguous!?

For value initialization, clause 8 and clause 13 nowhere defines that it 
respects value initialization, and hence the only correct conclusion is 
that value initialization does not do that IMO.




More information about the cfe-commits mailing list