]> granicus.if.org Git - clang/commitdiff
Parse: Don't crash when 'typename' shows up in an attribute
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 28 Dec 2014 22:28:32 +0000 (22:28 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 28 Dec 2014 22:28:32 +0000 (22:28 +0000)
isDeclarationSpecifier performs error recovers which jostles the token
stream.  Specifically, TryAnnotateTypeOrScopeToken will end up consuming
a typename token which will confuse the attribute parsing machinery as
we no-longer have something identifier-like.

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

lib/Parse/ParseDecl.cpp
test/Parser/cxx-attributes.cpp
test/Parser/namespace-alias-attr.cpp

index 64665fc28713e776fa1e50e51a2c83bb349ed71f..c0c0d59c7c4d763888571bebf21f1ec8abbf64d2 100644 (file)
@@ -143,7 +143,8 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs,
         continue;
 
       // Expect an identifier or declaration specifier (const, int, etc.)
-      if (Tok.isNot(tok::identifier) && !isDeclarationSpecifier())
+      if (Tok.isNot(tok::identifier) && !isTypeQualifier() &&
+          !isKnownToBeTypeSpecifier(Tok))
         break;
 
       IdentifierInfo *AttrName = Tok.getIdentifierInfo();
index 6fd7f4f68a465adec87252164df41534e55c3342..8cba5bc2a178e9c2d2732434d1a78400a6922e69 100644 (file)
@@ -20,3 +20,5 @@ namespace PR17666 {
   typedef int __attribute__((aligned(int(1)))) T1;
   typedef int __attribute__((aligned(int))) T2; // expected-error {{expected '(' for function-style cast}}
 }
+
+__attribute((typename)) int x; // expected-error {{expected ')'}}
index 0baba8493d0fda59188defd75c7c41521d4df0a6..141a96c5ebeb10c386e187f0135c5419272c5bda 100644 (file)
@@ -4,5 +4,5 @@ namespace A
 {
 }
 
-namespace B __attribute__ (( static )) = A; // expected-error{{attributes cannot be specified on namespace alias}}
+namespace B __attribute__ (( const )) = A; // expected-error{{attributes cannot be specified on namespace alias}}