]> granicus.if.org Git - clang/commitdiff
Fix crash if a variable template specialization is used in a nested-name-specifier.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 4 Dec 2013 00:47:45 +0000 (00:47 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 4 Dec 2013 00:47:45 +0000 (00:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196335 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaCXXScopeSpec.cpp
test/SemaCXX/cxx1y-variable-templates_top_level.cpp

index e0eaf341adcc92ed82d785aad617264afeeda663..392656a5b69c990de70c9fb5ca10053a518f9eef 100644 (file)
@@ -3413,7 +3413,8 @@ def warn_cxx98_compat_template_outside_of_template : Warning<
   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<
index 13c9993bf4cd5af3614e8dbc79e2298388233cb9..58bde02d602b710a2430c137480152d34d0a46ae 100644 (file)
@@ -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<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;
   }
index 5af6c0ab5bf7b9c1123118888364f9b19f4f0f62..58aad34edd1d42ddd35d561937ca7e90a20c2d20 100644 (file)
@@ -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}}