From 04100943da4d678fbd4d2f3b151edfe71d88c26e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 26 Apr 2018 02:10:22 +0000 Subject: [PATCH] Diagnose missing template arguments for a variable template even when there is a preceding 'template' keyword. We only diagnose in the dependent case (wherein we used to crash). Another bug prevents the diagnostic from appearing in the non-template case. llvm-svn: 330894 --- clang/lib/Sema/SemaTemplate.cpp | 8 ++++++++ .../cxx1y-variable-templates_in_class.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 442a8ec6805d..788eaca67400 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4017,6 +4017,14 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS, assert(!R.empty() && "empty lookup results when building templateid"); assert(!R.isAmbiguous() && "ambiguous lookup when building templateid"); + // Non-function templates require a template argument list. + if (auto *TD = R.getAsSingle()) { + if (!TemplateArgs && !isa(TD)) { + diagnoseMissingTemplateArguments(TemplateName(TD), R.getNameLoc()); + return ExprError(); + } + } + auto AnyDependentArguments = [&]() -> bool { bool InstantiationDependent; return TemplateArgs && diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp index 6471cd841836..2e1c9a439692 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp @@ -379,3 +379,19 @@ int main() { } // end ns PR24473 #endif // CPP1Y + +namespace dependent_static_var_template { + struct A { + template static int n; // expected-note {{here}} + }; + int &r = A::template n; // FIXME: ill-formed + + template + int &f() { return T::template n; } // expected-error {{use of variable template 'n' requires template arguments}} + int &s = f(); // expected-note {{instantiation of}} + + namespace B { + template static int n; + } + int &t = B::template n; // FIXME: ill-formed +}