]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: C++23 range-for temps and ?: [PR119073]
authorJason Merrill <jason@redhat.com>
Tue, 4 Mar 2025 21:36:47 +0000 (16:36 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 4 Mar 2025 23:18:39 +0000 (18:18 -0500)
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.

gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp0x/range-for39.C [new file with mode: 0644]

index be9b0cf62f103bc7f7289e0384431c2c38c3ca09..f7b4cccb1c7a2b63c4fca7e6ca34713cb0b71506 100644 (file)
@@ -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 (file)
index 0000000..ebb6aca
--- /dev/null
@@ -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{}))
+    ;
+}