]> granicus.if.org Git - clang/commitdiff
Improve error recovery when presented with an ill-formed template-id
authorJohn McCall <rjmccall@apple.com>
Fri, 30 Jul 2010 06:26:29 +0000 (06:26 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 30 Jul 2010 06:26:29 +0000 (06:26 +0000)
(e.g. due to a broken template argument) following template parameters.

Fixes rdar://problem/8254267

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109853 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDeclCXX.cpp
test/SemaTemplate/class-template-id.cpp
test/SemaTemplate/deduction-crash.cpp

index e6db33120088b6fb98e37751e7eb87f04e0c8605..7ed07a277c11a4a8ac7d365ee6d452355af176c7 100644 (file)
@@ -680,7 +680,8 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
     // "FOO : BAR" is not a potential typo for "FOO::BAR".
     ColonProtectionRAIIObject X(*this);
 
-    ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true);
+    if (ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/0, true))
+      DS.SetTypeSpecError();
     if (SS.isSet())
       if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id))
         Diag(Tok, diag::err_expected_ident);
@@ -804,10 +805,13 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
   else
     TUK = Action::TUK_Reference;
 
-  if (!Name && !TemplateId && TUK != Action::TUK_Definition) {
-    // We have a declaration or reference to an anonymous class.
-    Diag(StartLoc, diag::err_anon_type_definition)
-      << DeclSpec::getSpecifierName(TagType);
+  if (!Name && !TemplateId && (DS.getTypeSpecType() == DeclSpec::TST_error ||
+                               TUK != Action::TUK_Definition)) {
+    if (DS.getTypeSpecType() != DeclSpec::TST_error) {
+      // We have a declaration or reference to an anonymous class.
+      Diag(StartLoc, diag::err_anon_type_definition)
+        << DeclSpec::getSpecifierName(TagType);
+    }
 
     SkipUntil(tok::comma, true);
 
index df5ef554f7aa6e135e79314b5255479bc06ad72c..50e0b00c1a3238a7b8d9113ee431936c7bd307cd 100644 (file)
@@ -41,3 +41,7 @@ typedef N::C<float> c2;
 template<typename T> struct Foo { }; // expected-note{{template is declared here}}
 
 void f(void) { Foo bar; } // expected-error{{without a template argument list}}
+
+// rdar://problem/8254267
+template <typename T> class Party;
+template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}
index 1860c7577c79fe7fce5101c3d13a41495cc5fff3..8f4b7281818df17c6db10f526505f25dbfb66df8 100644 (file)
@@ -4,7 +4,7 @@
 
 // Note that the error count below doesn't matter. We just want to
 // make sure that the parser doesn't crash.
-// CHECK: 16 errors
+// CHECK: 15 errors
 template<a>
 struct int_;