]> granicus.if.org Git - clang/commitdiff
Don't check for triviality on fields of templated records. We can't know the
authorNick Lewycky <nicholas@mxc.ca>
Tue, 25 Jun 2013 23:22:23 +0000 (23:22 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Tue, 25 Jun 2013 23:22:23 +0000 (23:22 +0000)
answer until after instantiation. Fixes PR16061!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184890 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/cxx0x-nontrivial-union.cpp

index a5092d5a389d9a2d2b723661df0f548e82fb4999..08e8cb798acb53cfc9e7607c217f01495e2b822e 100644 (file)
@@ -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<RecordType>()) {
index 0e4add84955e9ded77a10c908043249fabfcbccb..db296bd57d71864ffc0b327b765897a032c3baee 100644 (file)
@@ -122,3 +122,25 @@ namespace optional {
     o2 = optional<non_trivial>();
   }
 }
+
+namespace pr16061 {
+  struct X { X(); };
+
+  template<typename T> struct Test1 {
+    union {
+      struct {
+        X x;
+      };
+    };
+  };
+
+  template<typename T> struct Test2 {
+    union {
+      struct {  // expected-note {{default constructor of 'Test2<pr16061::X>' is implicitly deleted because variant field '' has a non-trivial default constructor}}
+        T x;
+      };
+    };
+  };
+
+  Test2<X> t2x;  // expected-error {{call to implicitly-deleted default constructor of 'Test2<pr16061::X>'}}
+}