From: David Majnemer Date: Mon, 29 Dec 2014 05:17:46 +0000 (+0000) Subject: Sema: Don't crash when solitary :: token appears before { in struct def X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7e277784b3f61d19b96fb47acbb916fce58c772;p=clang Sema: Don't crash when solitary :: token appears before { in struct def hasDeclaratorForAnonDecl, getDeclaratorForAnonDecl and getTypedefNameForAnonDecl are expected to handle the case where NamedDeclOrQualifier holds the wrong type or nothing at all. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224912 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index cdba3bda80..12e0354bef 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2823,16 +2823,18 @@ public: bool hasDeclaratorForAnonDecl() const { return dyn_cast_or_null( - NamedDeclOrQualifier.get()); + NamedDeclOrQualifier.dyn_cast()); } DeclaratorDecl *getDeclaratorForAnonDecl() const { - return hasExtInfo() ? nullptr : dyn_cast_or_null( - NamedDeclOrQualifier.get()); + return hasExtInfo() ? nullptr + : dyn_cast_or_null( + NamedDeclOrQualifier.dyn_cast()); } TypedefNameDecl *getTypedefNameForAnonDecl() const { - return hasExtInfo() ? nullptr : dyn_cast_or_null( - NamedDeclOrQualifier.get()); + return hasExtInfo() ? nullptr + : dyn_cast_or_null( + NamedDeclOrQualifier.dyn_cast()); } void setDeclaratorForAnonDecl(DeclaratorDecl *DD) { NamedDeclOrQualifier = DD; } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 834f157e04..7264d82774 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -11790,7 +11790,7 @@ CreateNewDecl: // CheckMemberSpecialization, below. if (!isExplicitSpecialization && (TUK == TUK_Definition || TUK == TUK_Declaration) && - diagnoseQualifiedDeclaration(SS, DC, OrigName, NameLoc)) + diagnoseQualifiedDeclaration(SS, DC, OrigName, Loc)) Invalid = true; New->setQualifierInfo(SS.getWithLocInContext(Context)); diff --git a/test/CXX/dcl.decl/dcl.meaning/p1.cpp b/test/CXX/dcl.decl/dcl.meaning/p1.cpp index 5747380f28..aea14b3f51 100644 --- a/test/CXX/dcl.decl/dcl.meaning/p1.cpp +++ b/test/CXX/dcl.decl/dcl.meaning/p1.cpp @@ -43,3 +43,6 @@ namespace NS { template struct NS::Y { }; // expected-warning{{extra qualification on member 'Y'}} 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}}