On Thu, May 21, 2026 at 05:28:03PM +0200, Jakub Jelinek wrote:
> > Before C++26, a non-trivial variant member ctor makes t's deleted, so I
> > guess triviality never mattered?
> 
> For ctor with the exception of variant member with DMI, but then the default
> ctor is marked non-trivial because of
>               if (trivial_p)
>                 *trivial_p = false;
> in the DECL_INITIAL (field) walk_field_subobs handling.
> So shall I turn this
> > 
> > > +   if (cxx_dialect < cxx26
> > > +       || TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
> 
> into
>         if (TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
> ?

Tested incremental
--- gcc/cp/class.cc.jj  2026-05-20 22:41:11.372062501 +0200
+++ gcc/cp/class.cc     2026-05-21 17:35:59.834804002 +0200
@@ -3912,9 +3912,12 @@ check_field_decl (tree field,
            |= TYPE_HAS_COMPLEX_MOVE_ASSIGN (type);
          TYPE_HAS_COMPLEX_MOVE_CTOR (t) |= TYPE_HAS_COMPLEX_MOVE_CTOR (type);
          /* In C++26, triviality of default ctor or dtor of a variant member
-            doesn't matter for triviality of the t's default ctor or dtor.  */
-         if (cxx_dialect < cxx26
-             || TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
+            doesn't matter for triviality of the t's default ctor or dtor.
+            Before C++26, non-trivial default ctor or dtor of a variant
+            member makes it deleted with the exception of default ctor
+            when DMI is present, but in that case default ctor is
+            non-trivial.   */
+         if (TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
            {
              TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
                |= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type);

and it didn't regress anything in
GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make -j32 -k check-g++

        Jakub

Reply via email to