diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-02-22 09:06:26 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-02-22 09:06:26 +0000 |
| commit | 2386c8b2211f3708cb475ffbcfb38df127559bb1 (patch) | |
| tree | 0d6f683dad532c515677d3f2611959b912509a8b /clang | |
| parent | 44c247f0f009eec70a193335c8a353d6f8602bfd (diff) | |
| download | bcm5719-llvm-2386c8b2211f3708cb475ffbcfb38df127559bb1.tar.gz bcm5719-llvm-2386c8b2211f3708cb475ffbcfb38df127559bb1.zip | |
Per the grammar in [dcl.dcl]p1, a simple-declaration can only have attributes
if it has declarators. We were missing the check for this in a couple of places.
llvm-svn: 175876
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseTemplate.cpp | 13 | ||||
| -rw-r--r-- | clang/test/Parser/cxx0x-attributes.cpp | 5 |
3 files changed, 15 insertions, 8 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 4628f3dc17c..8ac3c504e2f 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1268,11 +1268,10 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(StmtVector &Stmts, Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(StmtVector &Stmts, unsigned Context, SourceLocation &DeclEnd, - ParsedAttributesWithRange &attrs, + ParsedAttributesWithRange &Attrs, bool RequireSemi, ForRangeInit *FRI) { // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this); - DS.takeAttributesFrom(attrs); ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none, getDeclSpecContextFromDeclaratorContext(Context)); @@ -1280,6 +1279,7 @@ Parser::ParseSimpleDeclaration(StmtVector &Stmts, unsigned Context, // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };" // declaration-specifiers init-declarator-list[opt] ';' if (Tok.is(tok::semi)) { + ProhibitAttributes(Attrs); DeclEnd = Tok.getLocation(); if (RequireSemi) ConsumeToken(); Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, @@ -1288,6 +1288,7 @@ Parser::ParseSimpleDeclaration(StmtVector &Stmts, unsigned Context, return Actions.ConvertDeclToDeclGroup(TheDecl); } + DS.takeAttributesFrom(Attrs); return ParseDeclGroup(DS, Context, /*FunctionDefs=*/ false, &DeclEnd, FRI); } diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index d7ae24960c1..32a78a73a89 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -208,22 +208,23 @@ Parser::ParseSingleDeclarationAfterTemplate( // the template parameters. ParsingDeclSpec DS(*this, &DiagsFromTParams); - // Move the attributes from the prefix into the DS. - if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) - ProhibitAttributes(prefixAttrs); - else - DS.takeAttributesFrom(prefixAttrs); - ParseDeclarationSpecifiers(DS, TemplateInfo, AS, getDeclSpecContextFromDeclaratorContext(Context)); if (Tok.is(tok::semi)) { + ProhibitAttributes(prefixAttrs); DeclEnd = ConsumeToken(); Decl *Decl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS); DS.complete(Decl); return Decl; } + // Move the attributes from the prefix into the DS. + if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) + ProhibitAttributes(prefixAttrs); + else + DS.takeAttributesFrom(prefixAttrs); + // Parse the declarator. ParsingDeclarator DeclaratorInfo(*this, DS, (Declarator::TheContext)Context); ParseDeclarator(DeclaratorInfo); diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index ac847a4893e..4e7ac16cc5d 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -88,6 +88,11 @@ class [[]] [[]] final_class_another [[]] struct with_init_declarators {} init_declarator; [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}} +template<typename> [[]] struct no_init_declarators_template; // expected-error {{an attribute list cannot appear here}} +void fn_with_structs() { + [[]] struct with_init_declarators {} init_declarator; + [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}} +} [[]]; struct ctordtor { [[]] ctordtor(); |

