diff options
author | Reid Kleckner <reid@kleckner.net> | 2014-07-14 18:19:58 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2014-07-14 18:19:58 +0000 |
commit | c582f0137e1f84ee198228a3e329befd8db0c34a (patch) | |
tree | 149ae6dcc979fb22cc54f72be64266d7124a505b /clang/lib | |
parent | 86f6934e27e9506b0b30c8f3fa23a017a0a50784 (diff) | |
download | bcm5719-llvm-c582f0137e1f84ee198228a3e329befd8db0c34a.tar.gz bcm5719-llvm-c582f0137e1f84ee198228a3e329befd8db0c34a.zip |
Revert "Improve error recovery around colon."
This reverts commit r212957. It broke the self-host on code like this
from LLVM's option library:
for (auto Arg: filtered(Id0, Id1, Id2))
llvm-svn: 212965
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 24 | ||||
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 31 |
2 files changed, 24 insertions, 31 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 89f4fc9fb92..09f78e5a755 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -2715,23 +2715,24 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, // typedef-name case tok::kw_decltype: case tok::identifier: { - // This identifier can only be a typedef name if we haven't already seen - // a type-specifier. Without this check we misparse: - // typedef int X; struct Y { short X; }; as 'short int'. - if (DS.hasTypeSpecifier()) - goto DoneWithDeclSpec; - // In C++, check to see if this is a scope specifier like foo::bar::, if // so handle it as such. This is important for ctor parsing. if (getLangOpts().CPlusPlus) { if (TryAnnotateCXXScopeToken(EnteringContext)) { - DS.SetTypeSpecError(); + if (!DS.hasTypeSpecifier()) + DS.SetTypeSpecError(); goto DoneWithDeclSpec; } if (!Tok.is(tok::identifier)) continue; } + // This identifier can only be a typedef name if we haven't already seen + // a type-specifier. Without this check we misparse: + // typedef int X; struct Y { short X; }; as 'short int'. + if (DS.hasTypeSpecifier()) + goto DoneWithDeclSpec; + // Check for need to substitute AltiVec keyword tokens. if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid)) break; @@ -4528,9 +4529,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D, // Member pointers get special handling, since there's no place for the // scope spec in the generic path below. if (getLangOpts().CPlusPlus && - (Tok.is(tok::coloncolon) || - (Tok.is(tok::identifier) && - (NextToken().is(tok::coloncolon) || NextToken().is(tok::less))) || + (Tok.is(tok::coloncolon) || Tok.is(tok::identifier) || Tok.is(tok::annot_cxxscope))) { bool EnteringContext = D.getContext() == Declarator::FileContext || D.getContext() == Declarator::MemberContext; @@ -4723,11 +4722,6 @@ void Parser::ParseDirectDeclarator(Declarator &D) { DeclaratorScopeObj DeclScopeObj(*this, D.getCXXScopeSpec()); if (getLangOpts().CPlusPlus && D.mayHaveIdentifier()) { - // Don't parse FOO:BAR as if it were a typo for FOO::BAR inside a class, in - // this context it is a bitfield. - ColonProtectionRAIIObject X(*this, - D.getContext() == Declarator::MemberContext); - // ParseDeclaratorInternal might already have parsed the scope. if (D.getCXXScopeSpec().isEmpty()) { bool EnteringContext = D.getContext() == Declarator::FileContext || diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6200363b3bc..cd2e3971884 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1239,8 +1239,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Parse the (optional) nested-name-specifier. CXXScopeSpec &SS = DS.getTypeSpecScope(); if (getLangOpts().CPlusPlus) { - // "FOO : BAR" is not a potential typo for "FOO::BAR". In this context it - // is a base-specifier-list. + // "FOO : BAR" is not a potential typo for "FOO::BAR". ColonProtectionRAIIObject X(*this); if (ParseOptionalCXXScopeSpecifier(SS, ParsedType(), EnteringContext)) @@ -1927,8 +1926,14 @@ void Parser::ParseCXXMemberDeclaratorBeforeInitializer( // declarator pure-specifier[opt] // declarator brace-or-equal-initializer[opt] // identifier[opt] ':' constant-expression - if (Tok.isNot(tok::colon)) + if (Tok.isNot(tok::colon)) { + // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it + // is a bitfield. + // FIXME: This should only apply when parsing the id-expression (see + // PR18587). + ColonProtectionRAIIObject X(*this); ParseDeclarator(DeclaratorInfo); + } if (!DeclaratorInfo.isFunctionDeclarator() && TryConsumeToken(tok::colon)) { BitfieldSize = ParseConstantExpression(); @@ -2010,14 +2015,6 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, return; } - // Turn on colon protection early, while parsing declspec, although there is - // nothing to protect there. It prevents from false errors if error recovery - // incorrectly determines where the declspec ends, as in the example: - // struct A { enum class B { C }; }; - // const int C = 4; - // struct D { A::B : C; }; - ColonProtectionRAIIObject X(*this); - // Access declarations. bool MalformedTypeSpec = false; if (!TemplateInfo.Kind && @@ -2131,11 +2128,13 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, if (MalformedTypeSpec) DS.SetTypeSpecError(); - ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class, - &CommonLateParsedAttrs); - - // Turn off colon protection that was set for declspec. - X.restore(); + { + // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it + // is a bitfield. + ColonProtectionRAIIObject X(*this); + ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC_class, + &CommonLateParsedAttrs); + } // If we had a free-standing type definition with a missing semicolon, we // may get this far before the problem becomes obvious. |