]> granicus.if.org Git - clang/commitdiff
PR18530: Don't assert when performing error recovery after a missing 'template<>...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 25 Jan 2014 21:32:06 +0000 (21:32 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 25 Jan 2014 21:32:06 +0000 (21:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200099 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/cxx1y-variable-templates_top_level.cpp

index 33cb77fa14fc6fcd75602a1b60826f6d7ade9e99..d4be61a22765e5dcc41f7ff6b96a8762b2a04083 100644 (file)
@@ -5129,7 +5129,7 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
           << SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc)
           << FixItHint::CreateInsertion(D.getDeclSpec().getLocStart(),
                                         "template<> ");
-      IsVariableTemplateSpecialization = true;
+      IsExplicitSpecialization = true;
       TemplateParams = TemplateParameterList::Create(Context, SourceLocation(),
                                                      SourceLocation(), 0, 0,
                                                      SourceLocation());
@@ -5206,18 +5206,13 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
 
     SetNestedNameSpecifier(NewVD, D);
 
-    // FIXME: Do we need D.getCXXScopeSpec().isSet()?
-    if (TemplateParams && TemplateParamLists.size() > 1 &&
-        (!IsVariableTemplateSpecialization || D.getCXXScopeSpec().isSet())) {
+    // If we have any template parameter lists that don't directly belong to
+    // the variable (matching the scope specifier), store them.
+    unsigned VDTemplateParamLists = TemplateParams ? 1 : 0;
+    if (TemplateParamLists.size() > VDTemplateParamLists)
       NewVD->setTemplateParameterListsInfo(
-          Context, TemplateParamLists.size() - 1, TemplateParamLists.data());
-    } else if (IsVariableTemplateSpecialization ||
-               (!TemplateParams && TemplateParamLists.size() > 0 &&
-                (D.getCXXScopeSpec().isSet()))) {
-      NewVD->setTemplateParameterListsInfo(Context,
-                                           TemplateParamLists.size(),
-                                           TemplateParamLists.data());
-    }
+          Context, TemplateParamLists.size() - VDTemplateParamLists,
+          TemplateParamLists.data());
 
     if (D.getDeclSpec().isConstexprSpecified())
       NewVD->setConstexpr(true);
index d2c42941347834fd98a360790fdfdbcd5652efab..526bef007873813ec4db100aada611390f3d5c1d 100644 (file)
@@ -436,3 +436,8 @@ namespace nested_name {
   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}}
 }
+
+namespace PR18530 {
+  template<typename T> int a;
+  int a<int>; // expected-error {{requires 'template<>'}}
+}