From: John McCall Date: Thu, 19 Aug 2010 23:06:02 +0000 (+0000) Subject: Correctly instantiate templates with non-type template arguments that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=766724566289e6951a90b6483f0d3e22fe4b9b52;p=clang Correctly instantiate templates with non-type template arguments that are local externs. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111570 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 6fc95634ab..cfae30c0ad 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2559,7 +2559,7 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, DeclContext *ParentDC = D->getDeclContext(); if (isa(D) || isa(D) || isa(D) || isa(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(CurrentInstantiationScope->getInstantiationOf(D)); diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp index d351eb4588..6f515916e4 100644 --- a/test/SemaTemplate/temp_arg_nontype.cpp +++ b/test/SemaTemplate/temp_arg_nontype.cpp @@ -203,3 +203,43 @@ namespace PR6964 { struct as_nview // expected-note{{while checking a default template argument used here}} { }; } + +// rdar://problem/8302138 +namespace test8 { + template 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 struct B { + C* p; + B() : p(cp) {} + }; + + void test2() { + extern C c02; + B<&c02> b02; + } + + extern C c03; + void test3() { + B<&c03> b03; + } +}