[cfe-commits] r113019 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-anonymous-union.cpp

Chandler Carruth chandlerc at gmail.com
Fri Sep 3 14:54:20 PDT 2010


Author: chandlerc
Date: Fri Sep  3 16:54:20 2010
New Revision: 113019

URL: http://llvm.org/viewvc/llvm-project?rev=113019&view=rev
Log:
Fix PR7402 when it strikes via template instantiation.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=113019&r1=113018&r2=113019&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Sep  3 16:54:20 2010
@@ -2274,6 +2274,11 @@
        Inits != InitsEnd; ++Inits) {
     CXXBaseOrMemberInitializer *Init = *Inits;
 
+    // Only instantiate written initializers, let Sema re-construct implicit
+    // ones.
+    if (!Init->isWritten())
+      continue;
+
     SourceLocation LParenLoc, RParenLoc;
     ASTOwningVector<Expr*> NewArgs(*this);
     llvm::SmallVector<SourceLocation, 4> CommaLocs;

Modified: cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp?rev=113019&r1=113018&r2=113019&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-anonymous-union.cpp Fri Sep  3 16:54:20 2010
@@ -47,3 +47,22 @@
 
   template void f<double>();
 }
+
+// Check for problems related to PR7402 that occur when template instantiation
+// instantiates implicit initializers.
+namespace PR7402 {
+  struct X {
+    union {
+      struct {
+        int x;
+        int y;
+      };
+      int v[2];
+    };
+
+    // Check that this requirement survives instantiation.
+    template <typename T> X(const T& t) : x(t), y(t) {}
+  };
+
+  X x(42.0);
+}





More information about the cfe-commits mailing list