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 | b9c64d84ea3edd5e2fffb0a2e85ca1308be4f429 (patch) | |
tree | 12059791aa88a3a99c5af19ca92d1c2300c67519 /lib/Sema/SemaDecl.cpp | |
parent | 437ee81e54f39c2363d5fe0ea155604c28adc615 (diff) |
C++11 allows unions to have static data members. Remove the corresponding
restriction and add some tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150721 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 9fa0349723..64a67d9a64 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/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(); } } |