@@ -1239,7 +1239,8 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
1239
1239
// Parse the (optional) nested-name-specifier.
1240
1240
CXXScopeSpec &SS = DS.getTypeSpecScope ();
1241
1241
if (getLangOpts ().CPlusPlus ) {
1242
- // "FOO : BAR" is not a potential typo for "FOO::BAR".
1242
+ // "FOO : BAR" is not a potential typo for "FOO::BAR". In this context it
1243
+ // is a base-specifier-list.
1243
1244
ColonProtectionRAIIObject X (*this );
1244
1245
1245
1246
if (ParseOptionalCXXScopeSpecifier (SS, ParsedType (), EnteringContext))
@@ -1926,14 +1927,8 @@ void Parser::ParseCXXMemberDeclaratorBeforeInitializer(
1926
1927
// declarator pure-specifier[opt]
1927
1928
// declarator brace-or-equal-initializer[opt]
1928
1929
// identifier[opt] ':' constant-expression
1929
- if (Tok.isNot (tok::colon)) {
1930
- // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it
1931
- // is a bitfield.
1932
- // FIXME: This should only apply when parsing the id-expression (see
1933
- // PR18587).
1934
- ColonProtectionRAIIObject X (*this );
1930
+ if (Tok.isNot (tok::colon))
1935
1931
ParseDeclarator (DeclaratorInfo);
1936
- }
1937
1932
1938
1933
if (!DeclaratorInfo.isFunctionDeclarator () && TryConsumeToken (tok::colon)) {
1939
1934
BitfieldSize = ParseConstantExpression ();
@@ -2015,6 +2010,14 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
2015
2010
return ;
2016
2011
}
2017
2012
2013
+ // Turn on colon protection early, while parsing declspec, although there is
2014
+ // nothing to protect there. It prevents from false errors if error recovery
2015
+ // incorrectly determines where the declspec ends, as in the example:
2016
+ // struct A { enum class B { C }; };
2017
+ // const int C = 4;
2018
+ // struct D { A::B : C; };
2019
+ ColonProtectionRAIIObject X (*this );
2020
+
2018
2021
// Access declarations.
2019
2022
bool MalformedTypeSpec = false ;
2020
2023
if (!TemplateInfo.Kind &&
@@ -2128,13 +2131,11 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
2128
2131
if (MalformedTypeSpec)
2129
2132
DS.SetTypeSpecError ();
2130
2133
2131
- {
2132
- // Don't parse FOO:BAR as if it were a typo for FOO::BAR, in this context it
2133
- // is a bitfield.
2134
- ColonProtectionRAIIObject X (*this );
2135
- ParseDeclarationSpecifiers (DS, TemplateInfo, AS, DSC_class,
2136
- &CommonLateParsedAttrs);
2137
- }
2134
+ ParseDeclarationSpecifiers (DS, TemplateInfo, AS, DSC_class,
2135
+ &CommonLateParsedAttrs);
2136
+
2137
+ // Turn off colon protection that was set for declspec.
2138
+ X.restore ();
2138
2139
2139
2140
// If we had a free-standing type definition with a missing semicolon, we
2140
2141
// may get this far before the problem becomes obvious.
0 commit comments