[cfe-commits] r80802 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/trivial-constructor-init.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Sep 3 12:38:58 PDT 2009


On Sep 3, 2009, at 7:55 AM, Douglas Gregor wrote:

>
> On Sep 2, 2009, at 10:10 AM, Fariborz Jahanian wrote:
>
>>
>
> We need to check that we aren't trying to zero-initialize a  
> reference type. For example, this code should be rejected (it  
> currently causes an assert):
>
>  struct X {
>    X() : value() { }
>
>    int &value;
>  };
>
> We have a similar issue with the implicitly-generated base  
> initializer, where we silently accept this ill-fomed code:
>
>  struct X {
>    X() { }
>
>    int &value;
>  };
>
> We do, however, get a truly beautiful diagnostic for the case where  
> we implicitly define the default constructor:
>
>  struct X {
>    int &value;
>  };
>
>  X x;
>
> /Users/dgregor/foo.cpp:5:3: error: cannot define the implicit default
>      constructor for 'struct X', because reference member 'value'  
> cannot be
>      default-initialized
> X x;
>  ^
> /Users/dgregor/foo.cpp:2:8: note: declared at
>  int &value;
>       ^
> 2 diagnostics generated.
>
> :)

All, and more, done in: http://llvm.org/viewvc/llvm-project?view=rev&revision=80934

- Fariborz

>
>
> 	- Doug




More information about the cfe-commits mailing list