[cfe-commits] r101725 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp test/CXX/temp/temp.spec/p5.cpp

Douglas Gregor dgregor at apple.com
Sun Apr 18 11:11:38 PDT 2010


Author: dgregor
Date: Sun Apr 18 13:11:38 2010
New Revision: 101725

URL: http://llvm.org/viewvc/llvm-project?rev=101725&view=rev
Log:
Make sure that we don't visit redeclarations of nested classes while
instantiating class members as part of an explicit
instantiation. Addresses a compilation problem in
Boost.Serialization.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/CXX/temp/temp.spec/p5.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=101725&r1=101724&r2=101725&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Sun Apr 18 13:11:38 2010
@@ -1446,7 +1446,10 @@
         }
       }      
     } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) {
-      if (Record->isInjectedClassName())
+      // Always skip the injected-class-name, along with any
+      // redeclarations of nested classes, since both would cause us
+      // to try to instantiate the members of a class twice.
+      if (Record->isInjectedClassName() || Record->getPreviousDeclaration())
         continue;
       
       MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();

Modified: cfe/trunk/test/CXX/temp/temp.spec/p5.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/p5.cpp?rev=101725&r1=101724&r2=101725&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/p5.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/p5.cpp Sun Apr 18 13:11:38 2010
@@ -27,3 +27,20 @@
 
 template float X0<float>::value; // expected-note{{previous explicit instantiation}}
 template float X0<float>::value; // expected-error{{duplicate explicit instantiation}}
+
+// Make sure that we don't get tricked by redeclarations of nested classes.
+namespace NestedClassRedecls {
+  template<typename T>
+  struct X {
+    struct Nested;
+    friend struct Nested;
+
+    struct Nested { 
+      Nested() {}
+    } nested;
+  };
+
+  X<int> xi;
+
+  template struct X<int>;
+}





More information about the cfe-commits mailing list