diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-03-06 23:06:59 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-03-06 23:06:59 +0000 |
commit | a71c129fb8052a143cbf548963a8db2150b0078e (patch) | |
tree | d8b30db92ff1c3483d2a52d8ffff57e2e777ce05 /lib/Sema/SemaDecl.cpp | |
parent | a6e27790acb6d06be6c1113ea94165c4b7e056cd (diff) |
Use the 'declaration does not declare anything' error when we see an anonymous struct/union declaration outside of a struct or union in C
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66303 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 50113ee4b7..5e7ce52ee8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -922,8 +922,14 @@ Sema::DeclTy *Sema::ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS) { if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Tag)) { if (!Record->getDeclName() && Record->isDefinition() && - DS.getStorageClassSpec() != DeclSpec::SCS_typedef) - return BuildAnonymousStructOrUnion(S, DS, Record); + DS.getStorageClassSpec() != DeclSpec::SCS_typedef) { + if (getLangOptions().CPlusPlus || + Record->getDeclContext()->isRecord()) + return BuildAnonymousStructOrUnion(S, DS, Record); + + Diag(DS.getSourceRange().getBegin(), diag::err_no_declarators) + << DS.getSourceRange(); + } // Microsoft allows unnamed struct/union fields. Don't complain // about them. @@ -1102,14 +1108,7 @@ Sema::DeclTy *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, Invalid = true; } } - } else { - // FIXME: Check GNU C semantics - if (Record->isUnion() && !Owner->isRecord()) { - Diag(Record->getLocation(), diag::err_anonymous_union_not_member) - << (int)getLangOptions().CPlusPlus; - Invalid = true; - } - } + } if (!Record->isUnion() && !Owner->isRecord()) { Diag(Record->getLocation(), diag::err_anonymous_struct_not_member) |