[cfe-commits] r85072 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/class/class.union/p1.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun Oct 25 15:31:45 PDT 2009


Author: cornedbee
Date: Sun Oct 25 17:31:45 2009
New Revision: 85072

URL: http://llvm.org/viewvc/llvm-project?rev=85072&view=rev
Log:
Make sure we actually have a definition before asking if it is implicit. Fixes PR4674.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/class/class.union/p1.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 25 17:31:45 2009
@@ -4940,12 +4940,16 @@
   case CXXDefaultConstructor:
     if (RD->hasUserDeclaredConstructor()) {
       typedef CXXRecordDecl::ctor_iterator ctor_iter;
-      for (ctor_iter ci = RD->ctor_begin(), ce = RD->ctor_end(); ci != ce; ++ci)
-        if (!ci->isImplicitlyDefined(Context)) {
+      for (ctor_iter ci = RD->ctor_begin(), ce = RD->ctor_end(); ci != ce;++ci){
+        const FunctionDecl *body = 0;
+        ci->getBody(body);
+        if (!body ||
+            !cast<CXXConstructorDecl>(body)->isImplicitlyDefined(Context)) {
           SourceLocation CtorLoc = ci->getLocation();
           Diag(CtorLoc, diag::note_nontrivial_user_defined) << QT << member;
           return;
         }
+      }
 
       assert(0 && "found no user-declared constructors");
       return;

Modified: cfe/trunk/test/CXX/class/class.union/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.union/p1.cpp?rev=85072&r1=85071&r2=85072&view=diff

==============================================================================
--- cfe/trunk/test/CXX/class/class.union/p1.cpp (original)
+++ cfe/trunk/test/CXX/class/class.union/p1.cpp Sun Oct 25 17:31:45 2009
@@ -16,6 +16,9 @@
 class Ctor {
   Ctor() { abort(); } // expected-note 3 {{because type 'class Ctor' has a user-declared constructor}}
 };
+class Ctor2 {
+  Ctor2(); // expected-note 3 {{because type 'class Ctor2' has a user-declared constructor}}
+};
 
 class CopyCtor {
   CopyCtor(CopyCtor &cc) { abort(); } // expected-note 3 {{because type 'class CopyCtor' has a user-declared copy constructor}}
@@ -34,6 +37,7 @@
   Virtual v; // expected-error {{union member 'v' has a non-trivial copy constructor}}
   VirtualBase vbase; // expected-error {{union member 'vbase' has a non-trivial copy constructor}}
   Ctor ctor; // expected-error {{union member 'ctor' has a non-trivial constructor}}
+  Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}}
   CopyCtor copyctor; // expected-error {{union member 'copyctor' has a non-trivial copy constructor}}
   CopyAssign copyassign; // expected-error {{union member 'copyassign' has a non-trivial copy assignment operator}}
   Dtor dtor; // expected-error {{union member 'dtor' has a non-trivial destructor}}
@@ -51,6 +55,9 @@
     Ctor ctor; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial constructor}}
   } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
   struct {
+    Ctor2 ctor2; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial constructor}}
+  } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
+  struct {
     CopyCtor copyctor; // expected-note {{because type 'struct U2::<anonymous>' has a member with a non-trivial copy constructor}}
   } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
   struct {
@@ -71,6 +78,8 @@
   } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}}
   struct s3 : Ctor { // expected-note {{because type 'struct U3::s3' has a base class with a non-trivial constructor}}
   } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
+  struct s3a : Ctor2 { // expected-note {{because type 'struct U3::s3a' has a base class with a non-trivial constructor}}
+  } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
   struct s4 : CopyCtor { // expected-note {{because type 'struct U3::s4' has a base class with a non-trivial copy constructor}}
   } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
   struct s5 : CopyAssign { // expected-note {{because type 'struct U3::s5' has a base class with a non-trivial copy assignment operator}}





More information about the cfe-commits mailing list