]> granicus.if.org Git - clang/commitdiff
Teach Sema how to instantiate a local function declaration properly. Fixes
authorJohn McCall <rjmccall@apple.com>
Sat, 6 Feb 2010 01:50:47 +0000 (01:50 +0000)
committerJohn McCall <rjmccall@apple.com>
Sat, 6 Feb 2010 01:50:47 +0000 (01:50 +0000)
PR 5517.

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

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-declref.cpp

index 66a8b1f1e6120f75309b5462b39ab7027be7403d..244b5f511b8db3cfa7ac1ef2dad50bce646a4efc 100644 (file)
@@ -738,9 +738,14 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
   if (T.isNull())
     return 0;
 
-  // Build the instantiated method declaration.
-  DeclContext *DC = SemaRef.FindInstantiatedContext(D->getDeclContext(),
-                                                    TemplateArgs);
+  // If we're instantiating a local function declaration, put the result
+  // in the owner;  otherwise we need to find the instantiated context.
+  DeclContext *DC;
+  if (D->getDeclContext()->isFunctionOrMethod())
+    DC = Owner;
+  else
+    DC = SemaRef.FindInstantiatedContext(D->getDeclContext(), TemplateArgs);
+
   FunctionDecl *Function =
       FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(),
                            D->getDeclName(), T, D->getTypeSourceInfo(),
index da8b263ab3abe59f70c98cee123162d8af0baa38..f883b9361b66eab3ed08c0ba46030de49713f24f 100644 (file)
@@ -87,3 +87,11 @@ struct smart_ptr {
 void test_smart_ptr(smart_ptr<int> p) {
   if (p) { }
 }
+
+// PR5517
+namespace test0 {
+  template <int K> struct X {
+    X() { extern void x(); }
+  };
+  void g() { X<2>(); }
+}