From: David Majnemer Date: Mon, 29 Dec 2014 19:19:18 +0000 (+0000) Subject: Parse: Ignore '::' in 'struct :: {' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b5d324b6735b592ecd315f4a085ba753c3e9a82;p=clang Parse: Ignore '::' in 'struct :: {' Let's pretend that we didn't see the '::' instead of go on believing that we've got some anonymous, but globally qualified, struct. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224945 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 12e0354bef..cdba3bda80 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2823,18 +2823,16 @@ public: bool hasDeclaratorForAnonDecl() const { return dyn_cast_or_null( - NamedDeclOrQualifier.dyn_cast()); + NamedDeclOrQualifier.get()); } DeclaratorDecl *getDeclaratorForAnonDecl() const { - return hasExtInfo() ? nullptr - : dyn_cast_or_null( - NamedDeclOrQualifier.dyn_cast()); + return hasExtInfo() ? nullptr : dyn_cast_or_null( + NamedDeclOrQualifier.get()); } TypedefNameDecl *getTypedefNameForAnonDecl() const { - return hasExtInfo() ? nullptr - : dyn_cast_or_null( - NamedDeclOrQualifier.dyn_cast()); + return hasExtInfo() ? nullptr : dyn_cast_or_null( + NamedDeclOrQualifier.get()); } void setDeclaratorForAnonDecl(DeclaratorDecl *DD) { NamedDeclOrQualifier = DD; } diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index dad1f0da2e..55f9245d58 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -219,13 +219,19 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, if (NextKind == tok::kw_new || NextKind == tok::kw_delete) return false; - // '::' - Global scope qualifier. - if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS)) - return true; + if (NextKind == tok::l_brace) { + // It is invalid to have :: {, consume the scope qualifier and pretend + // like we never saw it. + Diag(ConsumeToken(), diag::err_expected) << tok::identifier; + } else { + // '::' - Global scope qualifier. + if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS)) + return true; - CheckForLParenAfterColonColon(); + CheckForLParenAfterColonColon(); - HasScopeSpecifier = true; + HasScopeSpecifier = true; + } } if (Tok.is(tok::kw___super)) { diff --git a/test/CXX/dcl.decl/dcl.meaning/p1.cpp b/test/CXX/dcl.decl/dcl.meaning/p1.cpp index aea14b3f51..349f0d7058 100644 --- a/test/CXX/dcl.decl/dcl.meaning/p1.cpp +++ b/test/CXX/dcl.decl/dcl.meaning/p1.cpp @@ -44,5 +44,4 @@ namespace NS { template void NS::wibble(T) { } // expected-warning{{extra qualification on member 'wibble'}} } -// expected-warning@+1{{extra qualification on member}} struct ::{} a; // expected-error{{expected identifier}}