[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 23:51:29 PDT 2024


================
@@ -1395,7 +1395,8 @@ class CXXRecordDecl : public RecordDecl {
   bool allowConstDefaultInit() const {
     return !data().HasUninitializedFields ||
            !(data().HasDefaultedDefaultConstructor ||
-             needsImplicitDefaultConstructor());
+             needsImplicitDefaultConstructor()) ||
+           (isUnion() && isEmpty());
----------------
Sirraide wrote:

Er, why do we special-case empty unions here? Shouldn’t that just work automatically because an empty union has no fields at all and therefore no uninitialised fields either?

https://github.com/llvm/llvm-project/pull/96301


More information about the cfe-commits mailing list