[cfe-commits] r73782 - in /cfe/trunk: include/clang/AST/DeclCXX.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/DeclCXX.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/default-contructor-initializers.cpp

Fariborz Jahanian fjahanian at apple.com
Sat Jun 20 13:29:38 PDT 2009


On Jun 19, 2009, at 6:11 PM, Douglas Gregor wrote:

>
> On Jun 19, 2009, at 12:55 PM, Fariborz Jahanian wrote:
>
>> Author: fjahanian
>> Date: Fri Jun 19 14:55:27 2009
>> New Revision: 73782
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=73782&view=rev
>> Log:
>> Patch for implementation of C++'s object model. This is
>> work in progress.
>
> Cool.
>
>> Added:
>>   cfe/trunk/test/SemaCXX/default-contructor-initializers.cpp
>> Modified:
>>   cfe/trunk/include/clang/AST/DeclCXX.h
>>   cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>   cfe/trunk/lib/AST/DeclCXX.cpp
>>   cfe/trunk/lib/Sema/Sema.h
>>   cfe/trunk/lib/Sema/SemaDecl.cpp
>>   cfe/trunk/lib/Sema/SemaDeclCXX.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=73782&r1=73781&r2=73782&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- cfe/trunk/include/clang/AST/DeclCXX.h (original)
>> +++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Jun 19 14:55:27 2009
>> @@ -439,6 +439,9 @@
>>    TemplateOrInstantiation = Template;
>>  }
>>
>> +  /// getDefaultConstructor - Returns the default constructor for  
>> this class
>> +  CXXConstructorDecl *getDefaultConstructor(ASTContext &Context);
>> +
>>  /// getDestructor - Returns the destructor decl for this class.
>>  const CXXDestructorDecl *getDestructor(ASTContext &Context);
>>
>> @@ -638,6 +641,10 @@
>>  /// explicitly defaulted (i.e., defined with " = default") will have
>>  /// @c !Implicit && ImplicitlyDefined.
>>  bool ImplicitlyDefined : 1;
>> +
>> +  /// ImplicitMustBeDefined - Implicit constructor was used to  
>> create an
>> +  /// object of its class type. It must be defined.
>> +  bool ImplicitMustBeDefined : 1;
>
> I suspect that this flag won't live very long. For not-entirely- 
> unrelated reasons, I ended up adding a "Used" bit to all  
> declarations. We'll want to re-use that bit to mark when implicitly- 
> declared constructors are "used" and, therefore, need to be  
> implicitly defined.
>
> (Of course, my change to add the Used bit came after yours, so I  
> guess it's my problem <g>).
Yes, I noticed that you added the Used bit and it makes sense to use  
it and move the implicit ctor definition
stuff to MarkDeclarationReferences. I will work on it on Monday.

>
>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=73782&r1=73781&r2=73782&view=diff
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 19  
>> 14:55:27 2009
>> @@ -573,6 +573,14 @@
>> def err_param_default_argument_nonfunc : Error<
>>  "default arguments can only be specified for parameters in a  
>> function "
>>  "declaration">;
>> +def err_defining_default_ctor : Error<
>> +  "cannot define the default constructor for %0, because %1 does  
>> not "
>> +  "have any default constructor">;
>
> This is a nice error message. Could you add "base class" in there  
> before the %1, so the user knows we're talking about a base class  
> and not a member? Also, we should say "implicit default constructor"  
> to make it clear that it isn't the user's constructor.
>
> I wonder if it makes sense to have a note point at the base  
> specifier ("public X2") to show where the derivation came from. I  
> can imagine cases involving template types where it might not be  
> clear which base specifier results in this particular base class!

I think I am already doing this; sample:

default-constructor-initializers.cpp:14:4: error: cannot define the  
default constructor for 'struct X3', because member 'struct X2' does  
not have any implicit default constructor
X3 x3;  // expected-error {{cannot define the default constructor for  
'struct X3', because member 'struct X2' does not have any implicit  
default constructor}}
    ^
default-constructor-initializers.cpp:7:8: note: 'struct X2' declared  
here
struct X2  : X1 {  // expected-note {{'struct X2' declared here}} \
        ^

Other stuff is taken care of at:

http://llvm.org/viewvc/llvm-project?view=rev&revision=73833

- Thanks,
	Fariborz

>



More information about the cfe-commits mailing list