diff options
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 6 | ||||
-rw-r--r-- | test/Sema/pragma-pack-6.c | 16 |
3 files changed, 24 insertions, 5 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 869fedb00c..2b38718db9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8807,9 +8807,10 @@ CreateNewDecl: // many points during the parsing of a struct declaration (because // the #pragma tokens are effectively skipped over during the // parsing of the struct). - AddAlignmentAttributesForRecord(RD); - - AddMsStructLayoutForRecord(RD); + if (TUK == TUK_Definition) { + AddAlignmentAttributesForRecord(RD); + AddMsStructLayoutForRecord(RD); + } } if (ModulePrivateLoc.isValid()) { diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index cbfa1ba42e..c8e4501667 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1064,8 +1064,10 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, // Add alignment attributes if necessary; these attributes are checked when // the ASTContext lays out the structure. - AddAlignmentAttributesForRecord(NewClass); - AddMsStructLayoutForRecord(NewClass); + if (TUK == TUK_Definition) { + AddAlignmentAttributesForRecord(NewClass); + AddMsStructLayoutForRecord(NewClass); + } ClassTemplateDecl *NewTemplate = ClassTemplateDecl::Create(Context, SemanticContext, NameLoc, diff --git a/test/Sema/pragma-pack-6.c b/test/Sema/pragma-pack-6.c new file mode 100644 index 0000000000..40659c23bd --- /dev/null +++ b/test/Sema/pragma-pack-6.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify + +// Pragma pack handling with tag declarations + +struct X; + +#pragma pack(2) +struct X { int x; }; +struct Y; +#pragma pack() + +struct Y { int y; }; + +extern int check[__alignof(struct X) == 2 ? 1 : -1]; +extern int check[__alignof(struct Y) == 4 ? 1 : -1]; + |