On Mon, May 4, 2026 at 1:21 PM Jakub Jelinek <[email protected]> wrote:
>
> On Mon, May 04, 2026 at 12:13:39PM -0400, Eric Pimentel Aguiar wrote:
> > I believe that is for those cases where X is a non-union class, but
> > contains an anonymous union. The members of X not within an anonymous
union
> > would be those non-variant non-static data members referred in that
clause.
>
> What I mean is that the C++23
> "any non-variant non-static data member of const-qualified type (or array
thereof)
> with no brace-or-equal-initializer is not const-default-constructible"
> and C++26
> "X is a non-union class and any non-variant non-static data member of
const-qualified
> type (or possibly multidimensional array thereof) with no
brace-or-equal-initializer
> is not const-default-constructible"
> IMHO say exactly the same.  A union doesn't have any non-variant
non-static
> data members, only variant non-static data members, so the C++23
> wording implies that if the bullet is true, then X must be a non-union
> class.

Ah, I see what you mean now. That is somewhat redundant, unless the
definition of a
non-variant non-static data member includes a direct anonymous union
member. i.e. by
how variant members are defined here
https://eel.is/c++draft/class.union.anon#4 we have:

```
union U {
  int i;
  union {
    float f;
  };
};
```

The nested anonymous union is a non-static non-variant member of U, but the
member f
of that anonymous union is a non-static variant member of U. Can't really
think of how
that would make a difference, though

>
> > > More importantly, defaulted dtor would be previously deleted if it
had some
> > > variant subobject with deleted or inaccessible or non-trivial dtor, my
> > > understanding is that the paper wants to intentionally limit that to
> > > variant
> > > members with default initializer, but
> > > https://eel.is/c++draft/class.mem#class.dtor-7.2.2
> > > doesn't seem to do that.  For one, it doesn't apply to variant
members in
> > > anonymous unions because it only talks about union classes, so I
believe
> > > struct A { A (int); ~A () = delete; int a; };
> > > struct B { union { A a = 42; int b; }; };
> > > B::~B () per the new rules isn't deleted.  And for unions, guess
whether
> > >
> >
> > I believe that's because due to
> > https://eel.is/c++draft/class.default.ctor#2.4
> > Because "a" has a default member initializer and its class A has a
deleted
> > destructor,
>
> Ah, the anonymous union itself then has deleted dtor and since it is a
> non-variant member of B class, B has deleted dtor because of that.
> The only thing I'm wondering about is that the dtor is then deleted
because
> the subobject dtor is not accessible inside of the default ctor and wonder
> whether that has to always mean that it is also inaccessible inside of the
> dtor.
>
>         Jakub
>

Eric

Reply via email to