[llvm-branch-commits] [cfe-branch] r118553 - in /cfe/branches/Apple/whitney: lib/Sema/SemaTemplateInstantiate.cpp test/CodeGenCXX/template-instantiation.cpp

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:31:30 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:31:30 2010
New Revision: 118553

URL: http://llvm.org/viewvc/llvm-project?rev=118553&view=rev
Log:
Merge r118235:
--
Author: Argyrios Kyrtzidis <akyrtzi at gmail.com>
Date:   Thu Nov 4 03:18:57 2010 +0000

    Don't instantiate members not belonging in the semantic context of the template.
    e.g. for:

        template <int i> class A {
          class B *g;
        };

    'class B' has the template as lexical context but semantically it is
    introduced in namespace scope.

    Fixes rdar://8611125 & http://llvm.org/PR8505

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/branches/Apple/whitney/test/CodeGenCXX/template-instantiation.cpp

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaTemplateInstantiate.cpp?rev=118553&r1=118552&r2=118553&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaTemplateInstantiate.cpp Tue Nov  9 11:31:30 2010
@@ -1223,6 +1223,18 @@
   for (RecordDecl::decl_iterator Member = Pattern->decls_begin(),
          MemberEnd = Pattern->decls_end();
        Member != MemberEnd; ++Member) {
+    // Don't instantiate members not belonging in this semantic context.
+    // e.g. for:
+    // @code
+    //    template <int i> class A {
+    //      class B *g;
+    //    };
+    // @endcode
+    // 'class B' has the template as lexical context but semantically it is
+    // introduced in namespace scope.
+    if ((*Member)->getDeclContext() != Pattern)
+      continue;
+
     Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs);
     if (NewMember) {
       if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember))

Modified: cfe/branches/Apple/whitney/test/CodeGenCXX/template-instantiation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/CodeGenCXX/template-instantiation.cpp?rev=118553&r1=118552&r2=118553&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/CodeGenCXX/template-instantiation.cpp (original)
+++ cfe/branches/Apple/whitney/test/CodeGenCXX/template-instantiation.cpp Tue Nov  9 11:31:30 2010
@@ -109,3 +109,16 @@
     A<int>::foo();
   }
 }
+
+namespace PR8505 {
+// Hits an assertion due to bogus instantiation of class B.
+template <int i> class A {
+  class B* g;
+};
+class B {
+  void f () {}
+};
+// Should not instantiate class B since it is introduced in namespace scope.
+// CHECK-NOT: _ZN6PR85051AILi0EE1B1fEv
+template class A<0>;
+}





More information about the llvm-branch-commits mailing list