]> granicus.if.org Git - clang/commitdiff
When instantiating a function-local variable definition, introduce the
authorDouglas Gregor <dgregor@apple.com>
Mon, 3 May 2010 20:22:41 +0000 (20:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 3 May 2010 20:22:41 +0000 (20:22 +0000)
mapping from the declaration in the template to the instantiated
declaration before transforming the initializer, in case some crazy
lunatic decides to use a variable in its own initializer. Fixes PR7016.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-function-1.cpp

index 8974ecbdf42cba89af91a8bc375f07e102170ca9..a81e5e95f895b5d30d138b2412e579725107072c 100644 (file)
@@ -365,6 +365,9 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
     Owner->makeDeclVisibleInContext(Var);
   } else {
     Owner->addDecl(Var);
+    
+    if (Owner->isFunctionOrMethod())
+      SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Var);
   }
 
   // Link instantiations of static data members back to the template from
index 6e0d7115900430c1cf9fd1d31a197ab157308f2f..1bda43000b2a571d2469db79695315091fae725f 100644 (file)
@@ -220,3 +220,8 @@ namespace test0 {
   template <class T> class A { void foo(T array[10]); };
   template class A<int>;
 }
+
+namespace PR7016 {
+  template<typename T> void f() { T x = x; }
+  template void f<int>();
+}