r196335 - Fix crash if a variable template specialization is used in a nested-name-specifier.
Richard Smith
richard-llvm at metafoo.co.uk
Tue Dec 3 16:47:46 PST 2013
Author: rsmith
Date: Tue Dec 3 18:47:45 2013
New Revision: 196335
URL: http://llvm.org/viewvc/llvm-project?rev=196335&view=rev
Log:
Fix crash if a variable template specialization is used in a nested-name-specifier.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
cfe/trunk/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=196335&r1=196334&r2=196335&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 3 18:47:45 2013
@@ -3413,7 +3413,8 @@ def warn_cxx98_compat_template_outside_o
InGroup<CXX98Compat>, DefaultIgnore;
def err_non_type_template_in_nested_name_specifier : Error<
- "qualified name refers into a specialization of function template %0">;
+ "qualified name refers into a specialization of %select{function|variable}0 "
+ "template %1">;
def err_template_id_not_a_type : Error<
"template name refers to non-type template %0">;
def note_template_declared_here : Note<
Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=196335&r1=196334&r2=196335&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Tue Dec 3 18:47:45 2013
@@ -775,15 +775,15 @@ bool Sema::ActOnCXXNestedNameSpecifier(S
return false;
}
- // FIXME: Variable templates
+ TemplateDecl *TD = Template.get().getAsTemplateDecl();
if (Template.get().getAsOverloadedTemplate() || DTN ||
- isa<FunctionTemplateDecl>(Template.get().getAsTemplateDecl())) {
+ isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
SourceRange R(TemplateNameLoc, RAngleLoc);
if (SS.getRange().isValid())
R.setBegin(SS.getRange().getBegin());
Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
- << Template.get() << R;
+ << (TD && isa<VarTemplateDecl>(TD)) << Template.get() << R;
NoteAllFoundTemplates(Template.get());
return true;
}
Modified: cfe/trunk/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-variable-templates_top_level.cpp?rev=196335&r1=196334&r2=196335&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx1y-variable-templates_top_level.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-variable-templates_top_level.cpp Tue Dec 3 18:47:45 2013
@@ -433,9 +433,8 @@ namespace nested {
}
namespace nested_name {
- template<typename T> int a;
- // FIXME: This triggers a crash.
- //a<int>::b c;
+ template<typename T> int a; // expected-note {{variable template 'a' declared here}}
+ a<int>::b c; // expected-error {{qualified name refers into a specialization of variable template 'a'}}
class a<int> {}; // expected-error {{identifier followed by '<' indicates a class template specialization but 'a' refers to a variable template}}
enum a<int> {}; // expected-error {{expected identifier or '{'}} expected-warning {{does not declare anything}}
More information about the cfe-commits
mailing list