forked from OSchip/llvm-project
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:
parent
b35f46ce06
commit
f58efd9514
|
@ -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(
|
||||
|
|
|
@ -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}}
|
||||
|
|
Loading…
Reference in New Issue