[cfe-commits] r111570 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/temp_arg_nontype.cpp

John McCall rjmccall at apple.com
Thu Aug 19 16:06:02 PDT 2010


Author: rjmccall
Date: Thu Aug 19 18:06:02 2010
New Revision: 111570

URL: http://llvm.org/viewvc/llvm-project?rev=111570&view=rev
Log:
Correctly instantiate templates with non-type template arguments that
are local externs.  Fixes <rdar://problem/8302138>.


Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=111570&r1=111569&r2=111570&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Aug 19 18:06:02 2010
@@ -2559,7 +2559,7 @@
   DeclContext *ParentDC = D->getDeclContext();
   if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) ||
       isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D) ||
-      ParentDC->isFunctionOrMethod()) {
+      (ParentDC->isFunctionOrMethod() && ParentDC->isDependentContext())) {
     // D is a local of some kind. Look into the map of local
     // declarations to their instantiations.
     return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D));

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=111570&r1=111569&r2=111570&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp Thu Aug 19 18:06:02 2010
@@ -203,3 +203,43 @@
   struct as_nview<Sequence, I0>  // expected-note{{while checking a default template argument used here}}
   { };
 }
+
+// rdar://problem/8302138
+namespace test8 {
+  template <int* ip> struct A {
+    int* p;
+    A() : p(ip) {}
+  };
+
+  void test0() {
+    extern int i00;
+    A<&i00> a00;
+  }
+
+  extern int i01;
+  void test1() {
+    A<&i01> a01;
+  }
+
+
+  struct C {
+    int x;
+    char y;
+    double z;
+  };
+  
+  template <C* cp> struct B {
+    C* p;
+    B() : p(cp) {}
+  };
+
+  void test2() {
+    extern C c02;
+    B<&c02> b02;
+  }
+
+  extern C c03;
+  void test3() {
+    B<&c03> b03;
+  }
+}





More information about the cfe-commits mailing list