https://gcc.gnu.org/g:f2a7f845698bfb7aaded9ffacd7046ae25a8b1fc

commit r15-7819-gf2a7f845698bfb7aaded9ffacd7046ae25a8b1fc
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Mar 4 16:36:47 2025 -0500

    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:
---
 gcc/cp/call.cc                           |  2 +-
 gcc/testsuite/g++.dg/cpp0x/range-for39.C | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index be9b0cf62f10..f7b4cccb1c7a 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 000000000000..ebb6acafe7f3
--- /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{}))
+    ;
+}

Reply via email to