]> granicus.if.org Git - clang/commitdiff
Sema: Don't crash when solitary :: token appears before { in struct def
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 29 Dec 2014 05:17:46 +0000 (05:17 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 29 Dec 2014 05:17:46 +0000 (05:17 +0000)
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

include/clang/AST/Decl.h
lib/Sema/SemaDecl.cpp
test/CXX/dcl.decl/dcl.meaning/p1.cpp

index cdba3bda80f439f74fad69620945aadf0b421254..12e0354bef1982373a2646fd7379a7cbd08e1d16 100644 (file)
@@ -2823,16 +2823,18 @@ public:
 
   bool hasDeclaratorForAnonDecl() const {
     return dyn_cast_or_null<DeclaratorDecl>(
-        NamedDeclOrQualifier.get<NamedDecl *>());
+        NamedDeclOrQualifier.dyn_cast<NamedDecl *>());
   }
   DeclaratorDecl *getDeclaratorForAnonDecl() const {
-    return hasExtInfo() ? nullptr : dyn_cast_or_null<DeclaratorDecl>(
-                                  NamedDeclOrQualifier.get<NamedDecl *>());
+    return hasExtInfo() ? nullptr
+                        : dyn_cast_or_null<DeclaratorDecl>(
+                              NamedDeclOrQualifier.dyn_cast<NamedDecl *>());
   }
 
   TypedefNameDecl *getTypedefNameForAnonDecl() const {
-    return hasExtInfo() ? nullptr : dyn_cast_or_null<TypedefNameDecl>(
-                                  NamedDeclOrQualifier.get<NamedDecl *>());
+    return hasExtInfo() ? nullptr
+                        : dyn_cast_or_null<TypedefNameDecl>(
+                              NamedDeclOrQualifier.dyn_cast<NamedDecl *>());
   }
 
   void setDeclaratorForAnonDecl(DeclaratorDecl *DD) { NamedDeclOrQualifier = DD; }
index 834f157e04f4cb5024f4aaca2c7bdd9a0a855e3c..7264d82774ccc0fe2f8572efeff01aaeee9bdab2 100644 (file)
@@ -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));
index 5747380f2806d9b9af1f4a8c03d8ddf284ce2214..aea14b3f51eb383c49f164e2ce6ed05289d797cc 100644 (file)
@@ -43,3 +43,6 @@ namespace NS {
   template<typename T> struct NS::Y { }; // expected-warning{{extra qualification on member 'Y'}}
   template<typename T> void NS::wibble(T) { } // expected-warning{{extra qualification on member 'wibble'}}
 }
+
+// expected-warning@+1{{extra qualification on member}}
+struct ::{} a; // expected-error{{expected identifier}}