https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109768

            Bug ID: 109768
           Summary: Construct an anonymous union variable with a variant
                    member that has deleted the destructor should be
                    ill-formed
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xmh970252187 at gmail dot com
  Target Milestone: ---

#include <iostream>
struct B{
    B() = default;
    ~B() = delete;
};

int main(){
  union {B b;};
}

Both [class.dtor] p7 
> A defaulted destructor for a class X is defined as deleted if: 
>> X is a union-like class that has a variant member with a non-trivial 
>> destructor,

and [class.ctor.class.default.ctor] p2
> A defaulted default constructor for class X is defined as deleted if: 
>> - any potentially constructed subobject has a type with a destructor that is 
>> deleted or inaccessible from the defaulted default constructor.

The anonymous union object just has a deleted constructor and destructor. GCC
accepts this example while Clang rejects it.
  • [Bug c++/109768] New: Construct... xmh970252187 at gmail dot com via Gcc-bugs

Reply via email to