Hi Jakub,
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.
>
> > > 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.
This last bit here got me thinking last night. But I think that it is
possible for
such subobject dtor to be inaccessible from the containing object's default ctor
but accessible from the dtor. Using the friend specifier, we can construct
something _like_:
```
class M {
~M() = default;
friend X::~X();
public:
M() = default;
};
struct X {
M S;
};
```
Here, S's dtor is accessible in X's dtor, but not in it's default
ctor. But this is more
an edge case, I guess. I'm not sure how doing that could be made
useful. But it is
possible.
>
> Jakub
>
Eric