Support __attribute__((packed)) (along with other attributes) at the

end of a struct/class/union in C++, from Justin Bogner!

llvm-svn: 99811
This commit is contained in:
Douglas Gregor 2010-03-29 14:42:08 +00:00
parent cb6207f723
commit c48a10d652
6 changed files with 25 additions and 6 deletions

View File

@ -1761,7 +1761,8 @@ public:
virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
DeclPtrTy TagDecl,
SourceLocation LBrac,
SourceLocation RBrac) {
SourceLocation RBrac,
AttributeList *AttrList) {
}
//===---------------------------C++ Templates----------------------------===//

View File

@ -1579,10 +1579,11 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
// If attributes exist after class contents, parse them.
llvm::OwningPtr<AttributeList> AttrList;
if (Tok.is(tok::kw___attribute))
AttrList.reset(ParseGNUAttributes()); // FIXME: where should I put them?
AttrList.reset(ParseGNUAttributes());
Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl,
LBraceLoc, RBraceLoc);
LBraceLoc, RBraceLoc,
AttrList.get());
// C++ 9.2p2: Within the class member-specification, the class is regarded as
// complete within function bodies, default arguments,

View File

@ -2502,7 +2502,8 @@ public:
virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
DeclPtrTy TagDecl,
SourceLocation LBrac,
SourceLocation RBrac);
SourceLocation RBrac,
AttributeList *AttrList);
virtual void ActOnReenterTemplateScope(Scope *S, DeclPtrTy Template);
virtual void ActOnStartDelayedMemberDeclarations(Scope *S,

View File

@ -2174,7 +2174,8 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
DeclPtrTy TagDecl,
SourceLocation LBrac,
SourceLocation RBrac) {
SourceLocation RBrac,
AttributeList *AttrList) {
if (!TagDecl)
return;
@ -2182,7 +2183,7 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
ActOnFields(S, RLoc, TagDecl,
(DeclPtrTy*)FieldCollector->getCurFields(),
FieldCollector->getCurNumFields(), LBrac, RBrac, 0);
FieldCollector->getCurNumFields(), LBrac, RBrac, AttrList);
CheckCompletedCXXClass(
dyn_cast_or_null<CXXRecordDecl>(TagDecl.getAs<Decl>()));

View File

@ -37,6 +37,14 @@ struct __attribute__((packed)) packed_fas {
extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1];
extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1];
struct packed_after_fas {
char a;
int b[];
} __attribute__((packed));
extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1];
extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1];
// Alignment
struct __attribute__((aligned(8))) as1 {

View File

@ -48,6 +48,13 @@ struct H : G { };
SA(6, sizeof(H) == 1);
struct I {
char b;
int a;
} __attribute__((packed));
SA(6_1, sizeof(I) == 5);
// PR5580
namespace PR5580 {