From: Jason Merrill Date: Tue, 4 Mar 2025 21:36:47 +0000 (-0500) Subject: c++: C++23 range-for temps and ?: [PR119073] X-Git-Tag: basepoints/gcc-16~1734 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2a7f845698bfb7aaded9ffacd7046ae25a8b1fc;p=thirdparty%2Fgcc.git c++: C++23 range-for temps and ?: [PR119073] Here gimplification got confused because extend_temps_r messed up the types of the arms of a COND_EXPR. PR c++/119073 gcc/cp/ChangeLog: * call.cc (extend_temps_r): Preserve types of COND_EXPR arms. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/range-for39.C: New test. --- diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index be9b0cf62f1..f7b4cccb1c7 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -14902,7 +14902,7 @@ extend_temps_r (tree *tp, int *walk_subtrees, void *data) { tree set = build2 (MODIFY_EXPR, boolean_type_node, cur_cond_guard, boolean_true_node); - op = add_stmt_to_compound (set, op); + op = cp_build_compound_expr (set, op, tf_none); } }; walk_arm (TREE_OPERAND (*tp, 1)); diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for39.C b/gcc/testsuite/g++.dg/cpp0x/range-for39.C new file mode 100644 index 00000000000..ebb6acafe7f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for39.C @@ -0,0 +1,12 @@ +// PR c++/119073 +// { dg-do compile { target c++11 } } + +struct A { ~A (); }; +struct B { B (const A &a = A ()); int *begin (); int *end (); ~B (); }; + +void +foo (bool x) +{ + for (auto i : (x ? B{} : B{})) + ; +}