]> granicus.if.org Git - clang/commitdiff
Don't accidentally and silently accept C++11 attributes in decl-specifier-seqs
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 22 Feb 2013 09:15:49 +0000 (09:15 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 22 Feb 2013 09:15:49 +0000 (09:15 +0000)
in C++98.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175879 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
test/Parser/cxx-decl.cpp

index 8ac3c504e2f0eb1bb0e25d3561f5354c16337a84..6ab1540134a0e730e97ba2fda50df72221b18170 100644 (file)
@@ -2197,7 +2197,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
 
     case tok::l_square:
     case tok::kw_alignas:
-      if (!isCXX11AttributeSpecifier())
+      if (!getLangOpts().CPlusPlus11 || !isCXX11AttributeSpecifier())
         goto DoneWithDeclSpec;
 
       ProhibitAttributes(attrs);
index 90926a362beb54b25f6ec0eb48d2cce10cc85a05..f040b9bfff66f10a604aac75af919be7df87a8ab 100644 (file)
@@ -3186,6 +3186,8 @@ void Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
 ///       attribute-specifier-seq[opt] attribute-specifier
 void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
                                   SourceLocation *endLoc) {
+  assert(getLangOpts().CPlusPlus11);
+
   SourceLocation StartLoc = Tok.getLocation(), Loc;
   if (!endLoc)
     endLoc = &Loc;
index 24ba12751571813941eae21a56a2c4eddffde6f3..41d305b17642b08a09bed0cf9ac62505adbaeac0 100644 (file)
@@ -184,6 +184,9 @@ namespace PR15017 {
   template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' can not be defined in a type specifier}}
 }
 
+// Ensure we produce at least some diagnostic for attributes in C++98.
+[[]] struct S; // expected-error 2{{}}
+
 // PR8380
 extern ""      // expected-error {{unknown linkage language}}
 test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \