diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-09-19 13:34:43 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-09-19 13:34:43 +0000 |
commit | a495066d3cc094b3eb5edb4efbdb169da1f67841 (patch) | |
tree | 26d89d15add41d345743ee2b9ec4d71c0425519f /lib/Sema/SemaDeclCXX.cpp | |
parent | 9aca87d4b48058d56a48d62435ad6a871cc62ad1 (diff) |
In constructors, don't generate implicit initializers for members of anonymous structs contained within anonymous unions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140015 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b3ec3829b2..ecbff96297 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2262,6 +2262,19 @@ struct BaseAndFieldInfo { }; } +/// \brief Determine whether the given indirect field declaration is somewhere +/// within an anonymous union. +static bool isWithinAnonymousUnion(IndirectFieldDecl *F) { + for (IndirectFieldDecl::chain_iterator C = F->chain_begin(), + CEnd = F->chain_end(); + C != CEnd; ++C) + if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>((*C)->getDeclContext())) + if (Record->isUnion()) + return true; + + return false; +} + static bool CollectFieldInitializer(Sema &SemaRef, BaseAndFieldInfo &Info, FieldDecl *Field, IndirectFieldDecl *Indirect = 0) { @@ -2293,7 +2306,8 @@ static bool CollectFieldInitializer(Sema &SemaRef, BaseAndFieldInfo &Info, // Don't build an implicit initializer for union members if none was // explicitly specified. - if (Field->getParent()->isUnion()) + if (Field->getParent()->isUnion() || + (Indirect && isWithinAnonymousUnion(Indirect))) return false; // Don't try to build an implicit initializer if there were semantic |