[cfe-commits] r83583 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp test/SemaCXX/default-constructor-initializers.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Oct 8 15:15:49 PDT 2009


Author: fjahanian
Date: Thu Oct  8 17:15:49 2009
New Revision: 83583

URL: http://llvm.org/viewvc/llvm-project?rev=83583&view=rev
Log:
Fix up error reporting when object cannot be constructed 
because of missing default constructor of a member.
Fixes pr5154.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp
    cfe/trunk/test/SemaCXX/default-constructor-initializers.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=83583&r1=83582&r2=83583&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Oct  8 17:15:49 2009
@@ -720,8 +720,9 @@
   "default arguments cannot be added to an out-of-line definition of a member "
   "of a %select{class template|class template partial specialization|nested "
   "class in a template}0">;
+def note_field_decl : Note<"member is declared here">;
 def err_defining_default_ctor : Error<
-  "cannot define the implicit default constructor for %0, because %select{base class|member}1 "
+  "cannot define the implicit default constructor for %0, because %select{base class|member's type}1 "
   "%2 does not have any default constructor">;
 def note_previous_class_decl : Note<
   "%0 declared here">;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=83583&r1=83582&r2=83583&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Oct  8 17:15:49 2009
@@ -2852,7 +2852,7 @@
         MarkDeclarationReferenced(CurrentLocation, BaseCtor);
       else {
         Diag(CurrentLocation, diag::err_defining_default_ctor)
-          << Context.getTagDeclType(ClassDecl) << 1
+          << Context.getTagDeclType(ClassDecl) << 0
           << Context.getTagDeclType(BaseClassDecl);
         Diag(BaseClassDecl->getLocation(), diag::note_previous_class_decl)
               << Context.getTagDeclType(BaseClassDecl);
@@ -2874,8 +2874,9 @@
           MarkDeclarationReferenced(CurrentLocation, FieldCtor);
         else {
           Diag(CurrentLocation, diag::err_defining_default_ctor)
-          << Context.getTagDeclType(ClassDecl) << 0 <<
+          << Context.getTagDeclType(ClassDecl) << 1 <<
               Context.getTagDeclType(FieldClassDecl);
+          Diag((*Field)->getLocation(), diag::note_field_decl);
           Diag(FieldClassDecl->getLocation(), diag::note_previous_class_decl)
           << Context.getTagDeclType(FieldClassDecl);
           err = true;

Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp?rev=83583&r1=83582&r2=83583&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp Thu Oct  8 17:15:49 2009
@@ -13,7 +13,7 @@
   void g() { }
   
   struct Inner { 
-    T value; 
+    T value; 	// expected-note {{member is declared here}}
   };
   
   static T value;

Modified: cfe/trunk/test/SemaCXX/default-constructor-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default-constructor-initializers.cpp?rev=83583&r1=83582&r2=83583&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/default-constructor-initializers.cpp (original)
+++ cfe/trunk/test/SemaCXX/default-constructor-initializers.cpp Thu Oct  8 17:15:49 2009
@@ -11,15 +11,15 @@
 
 struct X3 : public X2 {
 };
-X3 x3;  // expected-error {{cannot define the implicit default constructor for 'struct X3', because member 'struct X2' does not have any default constructor}}
+X3 x3;  // expected-error {{cannot define the implicit default constructor for 'struct X3', because base class 'struct X2' does not have any default constructor}}
 
 
 struct X4 {
-  X2 x2; 
+  X2 x2; 	// expected-note {{member is declared here}}
   X2 & rx2; // expected-note {{declared at}}
 };
 
-X4 x4; // expected-error {{cannot define the implicit default constructor for 'struct X4', because base class 'struct X2' does not have any default constructor}} \
+X4 x4; // expected-error {{cannot define the implicit default constructor for 'struct X4', because member's type 'struct X2' does not have any default constructor}} \
        // expected-error {{cannot define the implicit default constructor for 'struct X4', because reference member 'rx2' cannot be default-initialized}}
 
 





More information about the cfe-commits mailing list