Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk?
-- >8 -- We also need to avoid folding 'outer_nelts_check' when in a template context to prevent an ICE on the below testcase. This patch achieves this by replacing the fold_build2 call with build2 (cp_fully_fold will later fold the overall expression if appropriate). In passing, this patch removes an unnecessary call to convert on 'nelts' since it should always already be a size_t (and 'convert' isn't the best conversion entry point to use anyway since it doesn't take a complain parameter.) PR c++/111929 gcc/cp/ChangeLog: * init.cc (build_new_1): Remove unnecessary call to convert on 'nelts'. Use build2 instead of fold_build2 for 'outer_nelts_checks'. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent28a.C: New test. --- gcc/cp/init.cc | 8 ++++---- gcc/testsuite/g++.dg/template/non-dependent28a.C | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent28a.C diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 65d37c3c0c7..6444f0a8518 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -3261,7 +3261,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, max_outer_nelts = wi::udiv_trunc (max_size, inner_size); max_outer_nelts_tree = wide_int_to_tree (sizetype, max_outer_nelts); - size = build2 (MULT_EXPR, sizetype, size, convert (sizetype, nelts)); + size = build2 (MULT_EXPR, sizetype, size, nelts); if (TREE_CODE (cst_outer_nelts) == INTEGER_CST) { @@ -3293,9 +3293,9 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, - wi::clz (max_outer_nelts); max_outer_nelts = (max_outer_nelts >> shift) << shift; - outer_nelts_check = fold_build2 (LE_EXPR, boolean_type_node, - outer_nelts, - max_outer_nelts_tree); + outer_nelts_check = build2 (LE_EXPR, boolean_type_node, + outer_nelts, + max_outer_nelts_tree); } } diff --git a/gcc/testsuite/g++.dg/template/non-dependent28a.C b/gcc/testsuite/g++.dg/template/non-dependent28a.C new file mode 100644 index 00000000000..d32520c38ee --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent28a.C @@ -0,0 +1,8 @@ +// PR c++/111929 + +struct A { operator int(); }; + +template<class> +void f() { + new int[A()]; +} -- 2.42.0.482.g2e8e77cbac