diff options
author | Francois Pichet <pichet2000@gmail.com> | 2010-09-08 11:32:25 +0000 |
---|---|---|
committer | Francois Pichet <pichet2000@gmail.com> | 2010-09-08 11:32:25 +0000 |
commit | 538e0d0292cab16198a4fce5c388ff06adc74d0c (patch) | |
tree | 89e9318108ae96be16acddd090a30d2be38a1312 /lib/Sema/SemaDecl.cpp | |
parent | 36281c6fd792a254ade72caf825bad7b7c63b0e0 (diff) |
Allow type definitions inside anonymous struct/union in Microsoft mode.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113354 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2b42fb60fb..dbc758f1f2 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1898,10 +1898,16 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, } else if (RecordDecl *MemRecord = dyn_cast<RecordDecl>(*Mem)) { if (!MemRecord->isAnonymousStructOrUnion() && MemRecord->getDeclName()) { - // This is a nested type declaration. - Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type) - << (int)Record->isUnion(); - Invalid = true; + // Visual C++ allows type definition in anonymous struct or union. + if (getLangOptions().Microsoft) + Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type) + << (int)Record->isUnion(); + else { + // This is a nested type declaration. + Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type) + << (int)Record->isUnion(); + Invalid = true; + } } } else if (isa<AccessSpecDecl>(*Mem)) { // Any access specifier is fine. @@ -1915,9 +1921,17 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, DK = diag::err_anonymous_record_with_function; else if (isa<VarDecl>(*Mem)) DK = diag::err_anonymous_record_with_static; - Diag((*Mem)->getLocation(), DK) + + // Visual C++ allows type definition in anonymous struct or union. + if (getLangOptions().Microsoft && + DK == diag::err_anonymous_record_with_type) + Diag((*Mem)->getLocation(), diag::ext_anonymous_record_with_type) << (int)Record->isUnion(); + else { + Diag((*Mem)->getLocation(), DK) + << (int)Record->isUnion(); Invalid = true; + } } } } |