From: Richard Smith Date: Wed, 4 Dec 2013 00:47:45 +0000 (+0000) Subject: Fix crash if a variable template specialization is used in a nested-name-specifier. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c12954d772c74a9c56dd83b12fb5e43525721f64;p=clang Fix crash if a variable template specialization is used in a nested-name-specifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196335 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index e0eaf341ad..392656a5b6 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3413,7 +3413,8 @@ def warn_cxx98_compat_template_outside_of_template : Warning< InGroup, 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< diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index 13c9993bf4..58bde02d60 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -775,15 +775,15 @@ bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, return false; } - // FIXME: Variable templates + TemplateDecl *TD = Template.get().getAsTemplateDecl(); if (Template.get().getAsOverloadedTemplate() || DTN || - isa(Template.get().getAsTemplateDecl())) { + isa(TD) || isa(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(TD)) << Template.get() << R; NoteAllFoundTemplates(Template.get()); return true; } diff --git a/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/test/SemaCXX/cxx1y-variable-templates_top_level.cpp index 5af6c0ab5b..58aad34edd 100644 --- a/test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ b/test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -433,9 +433,8 @@ namespace nested { } namespace nested_name { - template int a; - // FIXME: This triggers a crash. - //a::b c; + template int a; // expected-note {{variable template 'a' declared here}} + a::b c; // expected-error {{qualified name refers into a specialization of variable template 'a'}} class a {}; // expected-error {{identifier followed by '<' indicates a class template specialization but 'a' refers to a variable template}} enum a {}; // expected-error {{expected identifier or '{'}} expected-warning {{does not declare anything}}