summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-29 23:12:23 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-29 23:12:23 +0000
commitf58efd951449c927cca700332631205f10795509 (patch)
treea71bcdc1c36760f8440f179719f7afcc628b2f5b /clang
parentb35f46ce062f664981b4ecfcb0abea90ce5431db (diff)
downloadbcm5719-llvm-f58efd951449c927cca700332631205f10795509.tar.gz
bcm5719-llvm-f58efd951449c927cca700332631205f10795509.zip
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Parse/ParseExprCXX.cpp12
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/p1.cpp2
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 55f9245d586..a6162e2d4c5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -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(
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/p1.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/p1.cpp
index 349f0d70580..cefee7b8dc4 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/p1.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/p1.cpp
@@ -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}}
OpenPOWER on IntegriCloud