r195828 - [Sema] Don't look for the instantiation of a local extern decl in a different

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Nov 27 00:34:15 PST 2013


Author: akirtzidis
Date: Wed Nov 27 02:34:14 2013
New Revision: 195828

URL: http://llvm.org/viewvc/llvm-project?rev=195828&view=rev
Log:
[Sema] Don't look for the instantiation of a local extern decl in a different
dependent context that the one we are instantiating, otherwise there will be an assertion.

rdar://15464547

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=195828&r1=195827&r2=195828&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Nov 27 02:34:14 2013
@@ -3427,7 +3427,9 @@ void Sema::BuildVariableInstantiation(
                                   : Sema::LookupOrdinaryName,
       Sema::ForRedeclaration);
 
-  if (NewVar->isLocalExternDecl() && OldVar->getPreviousDecl()) {
+  if (NewVar->isLocalExternDecl() && OldVar->getPreviousDecl() &&
+      (!OldVar->getPreviousDecl()->getDeclContext()->isDependentContext() ||
+       OldVar->getPreviousDecl()->getDeclContext()==OldVar->getDeclContext())) {
     // We have a previous declaration. Use that one, so we merge with the
     // right type.
     if (NamedDecl *NewPrev = FindInstantiatedDecl(

Modified: cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp?rev=195828&r1=195827&r2=195828&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-function-2.cpp Wed Nov 27 02:34:14 2013
@@ -64,3 +64,28 @@ namespace PR10273 {
     (f)(17);
   }
 }
+
+namespace rdar15464547 {
+  class A {
+    A();
+  };
+
+  template <typename R> class B {
+  public:
+    static void meth1();
+    static void meth2();
+  };
+
+  A::A() {
+    extern int compile_time_assert_failed;
+    B<int>::meth2();
+  }
+
+  template <typename R> void B<R>::meth1() {
+    extern int compile_time_assert_failed;
+  }
+
+  template <typename R> void B<R>::meth2() {
+    extern int compile_time_assert_failed;
+  }
+}





More information about the cfe-commits mailing list