From: Nick Lewycky Date: Tue, 25 Jun 2013 23:22:23 +0000 (+0000) Subject: Don't check for triviality on fields of templated records. We can't know the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dccd04d8611b9d25fd17444f20566773e657a7e6;p=clang Don't check for triviality on fields of templated records. We can't know the answer until after instantiation. Fixes PR16061! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184890 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a5092d5a38..08e8cb798a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -10748,8 +10748,8 @@ bool Sema::CheckNontrivialField(FieldDecl *FD) { assert(FD); assert(getLangOpts().CPlusPlus && "valid check only for C++"); - if (FD->isInvalidDecl()) - return true; + if (FD->isInvalidDecl() || FD->getType()->isDependentType()) + return false; QualType EltTy = Context.getBaseElementType(FD->getType()); if (const RecordType *RT = EltTy->getAs()) { diff --git a/test/SemaCXX/cxx0x-nontrivial-union.cpp b/test/SemaCXX/cxx0x-nontrivial-union.cpp index 0e4add8495..db296bd57d 100644 --- a/test/SemaCXX/cxx0x-nontrivial-union.cpp +++ b/test/SemaCXX/cxx0x-nontrivial-union.cpp @@ -122,3 +122,25 @@ namespace optional { o2 = optional(); } } + +namespace pr16061 { + struct X { X(); }; + + template struct Test1 { + union { + struct { + X x; + }; + }; + }; + + template struct Test2 { + union { + struct { // expected-note {{default constructor of 'Test2' is implicitly deleted because variant field '' has a non-trivial default constructor}} + T x; + }; + }; + }; + + Test2 t2x; // expected-error {{call to implicitly-deleted default constructor of 'Test2'}} +}