]> granicus.if.org Git - clang/commitdiff
Recover properly if a class member declaration starts with a scope specifier
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 9 May 2012 08:23:23 +0000 (08:23 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 9 May 2012 08:23:23 +0000 (08:23 +0000)
or template-id which can't be parsed.

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

lib/Parse/ParseDeclCXX.cpp
lib/Parse/Parser.cpp
test/SemaCXX/member-init.cpp
test/SemaTemplate/dependent-base-classes.cpp

index 730c345d80729033b8a460cfa306591171b6fc96..e7d4ac7c37b0d391941101d329a50263e4584f97 100644 (file)
@@ -1704,12 +1704,16 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   }
   
   // Access declarations.
+  bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
-      (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) &&
-      !TryAnnotateCXXScopeToken() &&
-      Tok.is(tok::annot_cxxscope)) {
-    bool isAccessDecl = false;
-    if (NextToken().is(tok::identifier))
+      (Tok.is(tok::identifier) || Tok.is(tok::coloncolon))) {
+    if (TryAnnotateCXXScopeToken())
+      MalformedTypeSpec = true;
+
+    bool isAccessDecl;
+    if (Tok.isNot(tok::annot_cxxscope))
+      isAccessDecl = false;
+    else if (NextToken().is(tok::identifier))
       isAccessDecl = GetLookAheadToken(2).is(tok::semi);
     else
       isAccessDecl = NextToken().is(tok::kw_operator);
@@ -1806,6 +1810,8 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   // Parse the common declaration-specifiers piece.
   ParsingDeclSpec DS(*this, TemplateDiags);
   DS.takeAttributesFrom(attrs);
+  if (MalformedTypeSpec)
+    DS.SetTypeSpecError();
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class,
                              &CommonLateParsedAttrs);
 
index e406b184a7991c23d5aa1c275b42edd3ca73b6b9..955f4558f8505390f0f3966e94ed9e0180b51f9f 100644 (file)
@@ -1420,8 +1420,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext, bool NeedType) {
 
 /// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
 /// annotates C++ scope specifiers and template-ids.  This returns
-/// true if the token was annotated or there was an error that could not be
-/// recovered from.
+/// true if there was an error that could not be recovered from.
 ///
 /// Note that this routine emits an error if you call it with ::new or ::delete
 /// as the current tokens, so only call it in contexts where these are invalid.
index c93c85bbf89adf9c6b022e8d2c4d1b0ce730b5f8..3ca41a05633ed78d2d4a0a42227fcadb195a4fd0 100644 (file)
@@ -28,7 +28,7 @@ template<> struct T<2> { template<int C, int D> using B = int; };
 const int C = 0, D = 0;
 struct S {
   int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
-  T<sizeof(as) / sizeof(int)> x; // expected-error {{requires a type specifier}}
+  T<sizeof(as) / sizeof(int)> x;
   // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid
   operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \
                       // expected-error {{array bound cannot be deduced from an in-class initializer}}
index 895eacc87edd78176f34fd45210103d2b1f7efd4..1853511bfc8f0d7c2779e563cf98a93fb866a052 100644 (file)
@@ -32,8 +32,7 @@ namespace PR6031 {
   template <class TT>
   struct FI2
   {
-    C<typename FI2::type> a; // expected-error{{no type named 'type' in 'FI2<TT>'}} \
-        // expected-error{{C++ requires a type specifier for all declarations}}
+    C<typename FI2::type> a; // expected-error{{no type named 'type' in 'FI2<TT>'}}
   };
 
   template<typename T>