diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-16 20:41:22 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-16 20:41:22 +0000 |
| commit | 429737556135b7ef26e078f877fe2437d8f20bbe (patch) | |
| tree | 209acf2c1cbbdd408b90f7713ed892fd3020a294 /clang/lib | |
| parent | ea8dbdeefda2f7cd1d7637d7fa0d7d7eef9f4112 (diff) | |
| download | bcm5719-llvm-429737556135b7ef26e078f877fe2437d8f20bbe.tar.gz bcm5719-llvm-429737556135b7ef26e078f877fe2437d8f20bbe.zip | |
C++11 allows unions to have static data members. Remove the corresponding
restriction and add some tests.
llvm-svn: 150721
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9fa03497235..64a67d9a64d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3920,20 +3920,24 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, } else if (SC == SC_None) SC = SC_Static; } - if (SC == SC_Static) { + if (SC == SC_Static && CurContext->isRecord()) { if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) { if (RD->isLocalClass()) Diag(D.getIdentifierLoc(), diag::err_static_data_member_not_allowed_in_local_class) << Name << RD->getDeclName(); - // C++ [class.union]p1: If a union contains a static data member, - // the program is ill-formed. - // - // We also disallow static data members in anonymous structs. - if (CurContext->isRecord() && (RD->isUnion() || !RD->getDeclName())) + // C++98 [class.union]p1: If a union contains a static data member, + // the program is ill-formed. C++11 drops this restriction. + if (RD->isUnion()) + Diag(D.getIdentifierLoc(), + getLangOptions().CPlusPlus0x + ? diag::warn_cxx98_compat_static_data_member_in_union + : diag::ext_static_data_member_in_union) << Name; + // We conservatively disallow static data members in anonymous structs. + else if (!RD->getDeclName()) Diag(D.getIdentifierLoc(), - diag::err_static_data_member_not_allowed_in_union_or_anon_struct) + diag::err_static_data_member_not_allowed_in_anon_struct) << Name << RD->isUnion(); } } |

