summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-24 21:25:53 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-24 21:25:53 +0000
commit232ee49c7b705dce2bfe5cc3a8691916b8a1c51a (patch)
tree1900cadab5ee2133c791163e5df055c8d5df528b /clang/lib/Sema/SemaDeclCXX.cpp
parent2120e2bd732b0e0612e97cf253480807d76174ed (diff)
downloadbcm5719-llvm-232ee49c7b705dce2bfe5cc3a8691916b8a1c51a.tar.gz
bcm5719-llvm-232ee49c7b705dce2bfe5cc3a8691916b8a1c51a.zip
C++11 [class.ctor]p5 says that
A defaulted default constructor for a class X is defined as deleted if [...] - X is a union and all of its variant members are of const-qualified type. A pedantic reading therefore says that union X { }; has a deleted default constructor, which is both silly and almost certainly unintended. Pretend as if this this read - X is a union with one or more variant members, and all of its variant members are of const-qualified type. llvm-svn: 151394
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 6512929c2f3..6d2f3b252b1 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -4531,7 +4531,8 @@ bool SpecialMemberDeletionInfo::shouldDeleteForField(FieldDecl *FD) {
}
// At least one member in each anonymous union must be non-const
- if (CSM == Sema::CXXDefaultConstructor && AllVariantFieldsAreConst)
+ if (CSM == Sema::CXXDefaultConstructor && AllVariantFieldsAreConst &&
+ FieldRecord->field_begin() != FieldRecord->field_end())
return true;
// Don't try to initialize the anonymous union
@@ -4611,7 +4612,10 @@ bool SpecialMemberDeletionInfo::shouldDeleteForField(FieldDecl *FD) {
/// A defaulted default constructor for a class X is defined as deleted if
/// X is a union and all of its variant members are of const-qualified type.
bool SpecialMemberDeletionInfo::shouldDeleteForAllConstMembers() {
- return CSM == Sema::CXXDefaultConstructor && inUnion() && AllFieldsAreConst;
+ // This is a silly definition, because it gives an empty union a deleted
+ // default constructor. Don't do that.
+ return CSM == Sema::CXXDefaultConstructor && inUnion() && AllFieldsAreConst &&
+ (MD->getParent()->field_begin() != MD->getParent()->field_end());
}
/// Determine whether a defaulted special member function should be defined as
OpenPOWER on IntegriCloud