]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: re-enable NSDMI CONSTRUCTOR folding [PR118355]
authorMarek Polacek <polacek@redhat.com>
Mon, 13 Jan 2025 20:09:14 +0000 (15:09 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 29 Jan 2025 15:16:27 +0000 (10:16 -0500)
commit8774d5076d0a30c0809dd96f3fdbec8f867eeac5
treea26edc94aa4b6980e1c92f2c3e89e44c5b24077f
parenta48161638efc44ff443bb85e7718e50fa0d1ca83
c++: re-enable NSDMI CONSTRUCTOR folding [PR118355]

In c++/102990 we had a problem where massage_init_elt got {},
digest_nsdmi_init turned that {} into { .value = (int) 1.0e+0 },
and we crashed in the call to fold_non_dependent_init because
a FIX_TRUNC_EXPR/FLOAT_EXPR got into tsubst*.  So we avoided
calling fold_non_dependent_init for a CONSTRUCTOR.

But that broke the following test, where we no longer fold the
CONST_DECL in
  { .type = ZERO }
to
  { .type = 0 }
and then process_init_constructor_array does:

            if (next != error_mark_node
                && (initializer_constant_valid_p (next, TREE_TYPE (next))
                    != null_pointer_node))
              {
                /* Use VEC_INIT_EXPR for non-constant initialization of
                   trailing elements with no explicit initializers.  */
                picflags |= PICFLAG_VEC_INIT;

because { .type = ZERO } isn't initializer_constant_valid_p.  Then we
create a VEC_INIT_EXPR and say we can't convert the argument.

So we have to fold the elements of the CONSTRUCTOR.  We just can't
instantiate the elements in a template.

This also fixes c++/118047.

PR c++/118047
PR c++/118355

gcc/cp/ChangeLog:

* typeck2.cc (massage_init_elt): Call fold_non_dependent_init
unless for a CONSTRUCTOR in a template.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/nsdmi-list10.C: New test.
* g++.dg/cpp0x/nsdmi-list9.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit e939005c496dfd4058fa57b6860bfadcabe4a111)
gcc/cp/typeck2.cc
gcc/testsuite/g++.dg/cpp0x/nsdmi-list10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi-list9.C [new file with mode: 0644]