Commit ee0b1ff6e0 for perl

commit ee0b1ff6e05e70a63078846f1d698398481ed12f
Author: Paul Evans <leonerd@leonerd.org.uk>
Date:   Sun Nov 15 22:02:20 2026 +0000

    Ensure that `foreach` + `builtin::indexed` does not alias list values

    This matches the pre-optimisation state in older perls, where a
    temporary list was created. Modifications of these temporary values are
    allowed but do not modify the original arguments passed in to `indexed`.

    Fixes [GH#25053]

diff --git a/lib/builtin.t b/lib/builtin.t
index fcdce4ad31..8c23449e92 100644
--- a/lib/builtin.t
+++ b/lib/builtin.t
@@ -421,6 +421,14 @@ package FetchStoreCounter {

     ok(eq_array(\@output, [qw( [0]=two [1]=one [2]=zero )]),
         'foreach + builtin::indexed reverse LIST' );
+
+    my $ten = 10;
+    foreach my ( $idx, $val ) ( builtin::indexed $ten ) {
+        $val++;
+    }
+
+    is($ten, 10,
+        'foreach + builtin::indexed creates copies, not aliases' );
 }

 # indexed + foreach + refalias (GH#24999)
diff --git a/pp_hot.c b/pp_hot.c
index 19db6dd14c..fb04903988 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -5241,7 +5241,7 @@ PP(pp_iter)
                     *itersvp = NULL;
                     croak("Use of freed value in iteration");
                 }
-                if (SvPADTMP(sv)) {
+                if (SvPADTMP(sv) || (pflags & OPpITER_INDEXED)) {
                     sv = newSVsv(sv);
                 }
                 else {