diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1c0c6f766729..e43c28af9b69 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1192,7 +1192,7 @@ static LinkageInfo getLVForLocalDecl(const NamedDecl *D, } else { const FunctionDecl *FD = cast(OuterD); if (!FD->isInlined() && - FD->getTemplateSpecializationKind() == TSK_Undeclared) + !isTemplateInstantiation(FD->getTemplateSpecializationKind())) return LinkageInfo::none(); LV = getLVForDecl(FD, computation); diff --git a/clang/test/CodeGenCXX/function-template-specialization.cpp b/clang/test/CodeGenCXX/function-template-specialization.cpp index eb099df14d00..7728f3dc7462 100644 --- a/clang/test/CodeGenCXX/function-template-specialization.cpp +++ b/clang/test/CodeGenCXX/function-template-specialization.cpp @@ -1,4 +1,8 @@ // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - | FileCheck %s + +// CHECK-DAG: _ZZN7PR219047GetDataIiEERKibE1i = internal global i32 4 +// CHECK-DAG: _ZZN7PR219047GetDataIiEERKibE1i_0 = internal global i32 2 + template T* next(T* ptr, const U& diff); @@ -24,3 +28,18 @@ void test2(int *iptr, double *dptr, int diff) { // CHECK: _Z4nextIdiEPT_S1_RKT0_ dptr = next(dptr, diff); } + +namespace PR21904 { +template +const int &GetData(bool); + +template <> +const int &GetData(bool b) { + static int i = 4; + if (b) { + static int i = 2; + return i; + } + return i; +} +}