Parse: Don't crash when 'typename' shows up in an attribute

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.

llvm-svn: 224903
This commit is contained in:
David Majnemer 2014-12-28 22:28:32 +00:00
parent 3087a2b949
commit 06039218f5
3 changed files with 5 additions and 2 deletions

View 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();

View 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 ')'}}

View 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}}