so that e.g. b can be incremented, so unwrap the TARGET_EXPRs
and force TARGET_EXPR with the cv-unqualified type which is
a hack replacement for a VAR_DECL in a lambda. */
+ tree btype = cv_unqualified (TREE_TYPE (b));
+ tree etype = cv_unqualified (TREE_TYPE (e));
if (TREE_CODE (b) == TARGET_EXPR)
b = TARGET_EXPR_INITIAL (b);
if (TREE_CODE (e) == TARGET_EXPR)
e = TARGET_EXPR_INITIAL (e);
- b = force_target_expr (cv_unqualified (TREE_TYPE (b)), b,
- tf_warning_or_error);
- e = force_target_expr (cv_unqualified (TREE_TYPE (e)), e,
- tf_warning_or_error);
+ b = force_target_expr (btype, b, tf_warning_or_error);
+ e = force_target_expr (etype, e, tf_warning_or_error);
tree w = build_stmt (loc, WHILE_STMT, NULL_TREE, NULL_TREE,
NULL_TREE, NULL_TREE, NULL_TREE);
tree r = get_target_expr (build_zero_cst (ptrdiff_type_node));
--- /dev/null
+// PR c++/124927
+// { dg-do run { target c++23 } }
+// { dg-options "" }
+
+#include <array>
+#include <ranges>
+
+constexpr std::array a { 1, 2, 3, 4, 5 };
+constexpr std::array b { 5, 4, 3, 2, 1 };
+
+int
+foo (int i)
+{
+ template for (constexpr auto z : std::views::zip (a, b)) // { dg-warning "'template for' only available with" "" { target c++23_down } }
+ if (i == get <0> (z))
+ return get <1> (z);
+ return 0;
+}
+
+int
+main ()
+{
+ for (int i = 1; i <= 5; ++i)
+ if (foo (i) != 6 - i)
+ __builtin_abort ();
+ if (foo (0) != 0 || foo (6) != 0)
+ __builtin_abort ();
+}