Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -3295,6 +3295,9 @@ "previous declaration of variable template partial specialization is here">; def err_var_spec_no_template : Error< "no variable template matches%select{| partial}0 specialization">; +def err_var_spec_no_template_but_method : Error< + "no variable template matches%select{| partial}0 specialization; " + "did you mean to use %1 as function template instead">; // C++ Function template specializations def err_function_template_spec_no_match : Error< Index: lib/Sema/SemaTemplate.cpp =================================================================== --- lib/Sema/SemaTemplate.cpp +++ lib/Sema/SemaTemplate.cpp @@ -2375,10 +2375,20 @@ // The template-id must name a variable template. VarTemplateDecl *VarTemplate = - dyn_cast(Name.getAsTemplateDecl()); - if (!VarTemplate) + dyn_cast_or_null(Name.getAsTemplateDecl()); + if (!VarTemplate) { + if (OverloadedTemplateStorage *OST = Name.getAsOverloadedTemplate()) { + OverloadedTemplateStorage::iterator I = OST->begin(); + OverloadedTemplateStorage::iterator IEnd = OST->end(); + if (I != IEnd) { + return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method) + << IsPartialSpecialization + << (*I)->getDeclName(); + } + } return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template) << IsPartialSpecialization; + } // Check for unexpanded parameter packs in any of the template arguments. for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) Index: test/SemaCXX/cxx1y-variable-templates_top_level.cpp =================================================================== --- test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -448,3 +448,9 @@ static_assert(x == 1, ""); #endif } + +namespace PR19169 { + template int* f(); + template void f(); + template<> int f; // expected-error {{no variable template matches specialization; did you mean to use 'f' as function template instead}} +}