[cfe-commits] r140015 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/special/class.init/class.base.init/p8-0x.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Mon Sep 19 06:34:43 PDT 2011
Author: rsmith
Date: Mon Sep 19 08:34:43 2011
New Revision: 140015
URL: http://llvm.org/viewvc/llvm-project?rev=140015&view=rev
Log:
In constructors, don't generate implicit initializers for members of anonymous structs contained within anonymous unions.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/special/class.init/class.base.init/p8-0x.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=140015&r1=140014&r2=140015&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Sep 19 08:34:43 2011
@@ -2262,6 +2262,19 @@
};
}
+/// \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 @@
// 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
Modified: cfe/trunk/test/CXX/special/class.init/class.base.init/p8-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/special/class.init/class.base.init/p8-0x.cpp?rev=140015&r1=140014&r2=140015&view=diff
==============================================================================
--- cfe/trunk/test/CXX/special/class.init/class.base.init/p8-0x.cpp (original)
+++ cfe/trunk/test/CXX/special/class.init/class.base.init/p8-0x.cpp Mon Sep 19 08:34:43 2011
@@ -48,4 +48,12 @@
K(int n) : n(n) {}
K(int n, bool) : ndc(n) {}
};
+ struct Nested {
+ Nested() {}
+ union {
+ struct {
+ NoDefaultCtor ndc;
+ };
+ };
+ };
}
More information about the cfe-commits
mailing list