summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2011-09-19 13:34:43 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2011-09-19 13:34:43 +0000
commitc94ec84a3dc28579ce6d31d59404903e23d3c1dd (patch)
treef25a5cb63b8c2f0526eccab46b79b46c344a5924 /clang/lib/Sema/SemaDeclCXX.cpp
parentcdcfbf26dc5ceb6bee6f146f4f405c27f14ebe09 (diff)
downloadbcm5719-llvm-c94ec84a3dc28579ce6d31d59404903e23d3c1dd.tar.gz
bcm5719-llvm-c94ec84a3dc28579ce6d31d59404903e23d3c1dd.zip
In constructors, don't generate implicit initializers for members of anonymous structs contained within anonymous unions.
llvm-svn: 140015
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b3ec3829b20..ecbff96297e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/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
OpenPOWER on IntegriCloud