https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111929
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:d80a26cca025877b7657fa355570bc301223b50b commit r14-4899-gd80a26cca025877b7657fa355570bc301223b50b Author: Patrick Palka <ppa...@redhat.com> Date: Tue Oct 24 18:03:17 2023 -0400 c++: non-dep array new-expr size [PR111929] This PR is another instance of NON_DEPENDENT_EXPR having acted as an "analysis barrier" for middle-end routines, and now that it's gone we're more prone to passing weird templated trees (that have a generic tree code) to middle-end routines which end up ICEing on such trees. In the testcase below the non-dependent array new-expr size 'x + 42' is expressed as an ordinary PLUS_EXPR, but whose operands have different types (since templated trees encode just the syntactic form of an expression devoid of e.g. implicit conversions). This type incoherency triggers an ICE from size_binop in build_new_1 due to a wide_int assert that expects the operand types to have the same precision. This patch fixes this by replacing our piecemeal folding of 'size' in build_new_1 with a single call to cp_fully_fold (which is a no-op in a template context) once 'size' is built up. PR c++/111929 gcc/cp/ChangeLog: * init.cc (build_new_1): Use convert, build2, build3 and cp_fully_fold instead of fold_convert, size_binop and fold_build3 when building up 'size'. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent28.C: New test.