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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=98423

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Here is an example which is valid (after
> https://cplusplus.github.io/CWG/issues/2084.html):
> struct S1 {
>     S1();
> };
> struct S {
>     S();
> };
> union U {
>     S s{};
>     S1 s1;
> } u;
> 
> The check in GCC for this seems to be off, if only the variant s is there,
> GCC (and clang) accepts it.
> 
> So the full check for the defect report was never really done (and it was
> not even mentioned in the defect report commentary either).

Yes, all of gcc, clang, edg and msvc reject cases like this.

It should not matter that S1 does not have a trivial default ctor, because the
default member initializer should make this equivalent to:

union U {
  S s;
  S1 s1;
  U() : s() { }
};

Having to write a user-provided constructor is annoying, because to do it
"right" in a generic std::lib template requires:

  constexpr U() noexcept(is_nothrow_default_constructible_v<S>) requires
default_initializable<S> { }

But that should be approximately how the defaulted default ctor is defined
automatically, without all that verbosity.

This is a dup of PR 98423, where Jakub pointed out the code that needs to
change, and what needs to happen.

Reply via email to