From: Sebastian Redl Date: Sun, 25 Oct 2009 22:31:45 +0000 (+0000) Subject: Make sure we actually have a definition before asking if it is implicit. Fixes PR4674. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38fd4d001182b0b125a42c3b7e83e9dbac50e8a5;p=clang Make sure we actually have a definition before asking if it is implicit. Fixes PR4674. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85072 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7b37df9cbe..11dbf042f2 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4940,12 +4940,16 @@ void Sema::DiagnoseNontrivial(const RecordType* T, CXXSpecialMember member) { 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(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; diff --git a/test/CXX/class/class.union/p1.cpp b/test/CXX/class/class.union/p1.cpp index 15c2634673..9c969c5b75 100644 --- a/test/CXX/class/class.union/p1.cpp +++ b/test/CXX/class/class.union/p1.cpp @@ -16,6 +16,9 @@ class VirtualBase : virtual Okay { // expected-note 3 {{because type 'class Virt 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 @@ union U1 { 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}} @@ -50,6 +54,9 @@ union U2 { struct { Ctor ctor; // expected-note {{because type 'struct U2::' 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::' 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::' has a member with a non-trivial copy constructor}} } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}} @@ -71,6 +78,8 @@ union U3 { } 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}}