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

            Bug ID: 100185
           Summary: transparent_union fails when the union has a
                    destructor
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gonzalobg88 at gmail dot com
  Target Milestone: ---

Example:

    union  __attribute__((transparent_union)) U {
        int* a;
        ~U() {}
    };

fails with:

    <source>:1:43: error: type transparent 'union U' cannot be made transparent 
    because the type of the first field has a different ABI from the class
overall
        1 | union  __attribute__((transparent_union)) U {
          |                                           ^

I think this should be allowed with the following semantics:

    void f(int*);
    void g(U&);
    void h(U);
    void j(int);

    {
        U u;
        f(u); // passes U as int*
        g(u); // passes U as U&
        h(u); // ERROR: U does not have a copy constructor
        j(u); // ERROR: cannot convert U to int

        //~U() called at the end of the scope
    }

Reply via email to