]> granicus.if.org Git - clang/commitdiff
Make sure that we don't visit redeclarations of nested classes while
authorDouglas Gregor <dgregor@apple.com>
Sun, 18 Apr 2010 18:11:38 +0000 (18:11 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 18 Apr 2010 18:11:38 +0000 (18:11 +0000)
instantiating class members as part of an explicit
instantiation. Addresses a compilation problem in
Boost.Serialization.

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

lib/Sema/SemaTemplateInstantiate.cpp
test/CXX/temp/temp.spec/p5.cpp

index 1943a2ae176f2f66af3d6f7516d1166fcb7af11d..a2bd37c0bbbce3c81823b15526ad6e93a79e1630 100644 (file)
@@ -1446,7 +1446,10 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
         }
       }      
     } 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();
index c37817cc49b8d489adb3842b34724b9091aa0245..ba99dd7093a20dd5225b88b7b10591be7a4d3c61 100644 (file)
@@ -27,3 +27,20 @@ template union X0<float>::Inner; // expected-error{{duplicate explicit instantia
 
 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>;
+}