Parse: Recover more gracefully from extra :: tokens before a {

Instead of crashing, recover by eating the extra trailing scope
qualifier.  This means we will treat 'struct A:: {' as 'struct A {'.

llvm-svn: 224966
This commit is contained in:
David Majnemer 2014-12-29 23:12:23 +00:00
parent b35f46ce06
commit f58efd9514
2 changed files with 13 additions and 1 deletions

View File

@ -442,7 +442,17 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS,
Next.setKind(tok::coloncolon);
}
}
if (Next.is(tok::coloncolon) && GetLookAheadToken(2).is(tok::l_brace)) {
// It is invalid to have :: {, consume the scope qualifier and pretend
// like we never saw it.
Token Identifier = Tok; // Stash away the identifier.
ConsumeToken(); // Eat the identifier, current token is now '::'.
Diag(PP.getLocForEndOfTokenConsumeToken(), diag::err_expected) << tok::identifier;
UnconsumeToken(Identifier); // Stick the identifier back.
Next = NextToken(); // Point Next at the '{' token.
}
if (Next.is(tok::coloncolon)) {
if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde) &&
!Actions.isNonTypeNestedNameSpecifier(

View File

@ -27,6 +27,7 @@ namespace NS {
struct X;
template<typename T> struct Y;
template<typename T> void wibble(T);
struct Z;
}
namespace NS {
// Under DR482, these are all valid, except for forward-declaring a struct
@ -45,3 +46,4 @@ namespace NS {
}
struct ::{} a; // expected-error{{expected identifier}}
struct NS::Z:: {} b; // expected-error{{expected identifier}}