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.

llvm-svn: 224912

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

index cdba3bd..12e0354 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 834f157..7264d82 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 5747380..aea14b3 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}}