r330894 - Diagnose missing template arguments for a variable template even when there is
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 25 19:10:22 PDT 2018
Author: rsmith
Date: Wed Apr 25 19:10:22 2018
New Revision: 330894
URL: http://llvm.org/viewvc/llvm-project?rev=330894&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=330894&r1=330893&r2=330894&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Apr 25 19:10:22 2018
@@ -4017,6 +4017,14 @@ ExprResult Sema::BuildTemplateIdExpr(con
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<TemplateDecl>()) {
+ if (!TemplateArgs && !isa<FunctionTemplateDecl>(TD)) {
+ diagnoseMissingTemplateArguments(TemplateName(TD), R.getNameLoc());
+ return ExprError();
+ }
+ }
+
auto AnyDependentArguments = [&]() -> bool {
bool InstantiationDependent;
return TemplateArgs &&
Modified: cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp?rev=330894&r1=330893&r2=330894&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-variable-templates_in_class.cpp Wed Apr 25 19:10:22 2018
@@ -379,3 +379,19 @@ int main() {
} // end ns PR24473
#endif // CPP1Y
+
+namespace dependent_static_var_template {
+ struct A {
+ template<int = 0> static int n; // expected-note {{here}}
+ };
+ int &r = A::template n; // FIXME: ill-formed
+
+ template<typename T>
+ int &f() { return T::template n; } // expected-error {{use of variable template 'n' requires template arguments}}
+ int &s = f<A>(); // expected-note {{instantiation of}}
+
+ namespace B {
+ template<int = 0> static int n;
+ }
+ int &t = B::template n; // FIXME: ill-formed
+}
More information about the cfe-commits
mailing list