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 | 4ad4b58639472b729d8b67b7315abf8f258fa315 (patch) | |
| tree | 5e3540206b8eda97037eb3102b437566c216d673 /clang/lib/Sema/SemaDecl.cpp | |
| parent | 2907d2e419fff782066aa5b78698c6adc7b5e44a (diff) | |
| download | bcm5719-llvm-4ad4b58639472b729d8b67b7315abf8f258fa315.tar.gz bcm5719-llvm-4ad4b58639472b729d8b67b7315abf8f258fa315.zip | |
Allow type definitions inside anonymous struct/union in Microsoft mode.
llvm-svn: 113354
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 2b42fb60fbb..dbc758f1f2a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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; + } } } } |

