}
// 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
/// 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
// See also rdar://problem/8125400.
namespace empty {
- static union {}; // expected-error {{implicitly-deleted default constructor}} expected-note {{here}}
- static union { union {}; }; // expected-error {{implicitly-deleted default constructor}} expected-note {{here}}
+ static union {};
+ static union { union {}; };
static union { struct {}; };
- static union { union { union {}; }; }; // expected-error {{implicitly-deleted default constructor}} expected-note {{here}}
+ static union { union { union {}; }; };
static union { union { struct {}; }; };
- static union { struct { union {}; }; }; // expected-error {{implicitly-deleted default constructor}} expected-note {{here}}
+ static union { struct { union {}; }; };
static union { struct { struct {}; }; };
}