Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -3563,7 +3563,8 @@ ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, - bool AcceptInvalidDecl = false); + bool AcceptInvalidDecl = false, + const TemplateArgumentListInfo *TemplateArgs = nullptr); ExprResult BuildDeclarationNameExpr( const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, NamedDecl *FoundD = nullptr, Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -1621,6 +1621,13 @@ VarSpec->getTemplateKeywordLoc(), D, RefersToCapturedVariable, NameInfo.getLoc(), Ty, VK, FoundD, TemplateArgs); + } else if (isa(D) && cast(D)->isFunctionTemplateSpecialization()) { + FunctionDecl *FuncDecl = + cast(D); + E = DeclRefExpr::Create(Context, SS ? SS->getWithLocInContext(Context) + : NestedNameSpecifierLoc(), + FuncDecl->getPointOfInstantiation(), D, RefersToCapturedVariable, + NameInfo, Ty, VK, FoundD, TemplateArgs); } else { assert(!TemplateArgs && "No template arguments for non-variable" " template specialization references"); @@ -2697,12 +2704,13 @@ ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, - bool AcceptInvalidDecl) { + bool AcceptInvalidDecl, + const TemplateArgumentListInfo *TemplateArgs) { // If this is a single, fully-resolved result and we don't need ADL, // just build an ordinary singleton decl ref. if (!NeedsADL && R.isSingleResult() && !R.getAsSingle()) return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), R.getFoundDecl(), - R.getRepresentativeDecl(), nullptr, + R.getRepresentativeDecl(), TemplateArgs, AcceptInvalidDecl); // We only need to check the declaration if there's exactly one Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -1736,9 +1736,7 @@ CXXScopeSpec SS; SS.Adopt(QualifierLoc); - // FIXME: loses template args. - - return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); + return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, nullptr, TemplateArgs); } /// \brief Build a new expression in parentheses.