Commit bf6d87b3a4 for perl

commit bf6d87b3a468fb3b831c58858d39369b231499ce
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date:   Mon Oct 5 23:02:45 2026 +0100

    pat_re_eval.t: improve (??{ undef }) test

    An existing test checks for the correct warnings being generated when
    (??{...}) returns an undef value. Currently, this is mainly to check
    that a variable name isn't spuriously included in the message.

    Expand the test to check also that the warning identifies the correct
    line, and that it doesn't identify an op (the test actually already
    checks for the latter, but the test wasn't documented as doing so).

    In something like

        $s =~ /...(??{ $undef })/

    the retrieving of the returned undef value isn't being done by the
    PADSV op, and arguably neither is it being done by the match op.
    So check that the warning message doesn't contain an 'in foo' where foo
    is an operator description.

    I think a case could actually be made for the latter (i.e. to include
    "in pattern match (m//)".  But if the regex was being called from within
    XS code for example, then going for the latter would result in "use of
    uninitialialized value in subroutine entry", which would be more
    confusing than just leaving it blank.

    In any case, the motivation for this commit is to ensure that the
    refactoring I'm currently doing doesn't break anything by accident. So
    it reflects the current status quo.

diff --git a/t/re/pat_re_eval.t b/t/re/pat_re_eval.t
index d801013cf8..85c0f0789c 100644
--- a/t/re/pat_re_eval.t
+++ b/t/re/pat_re_eval.t
@@ -25,7 +25,7 @@ BEGIN {
 our @global;


-plan tests => 555;  # Update this when adding/deleting tests.
+plan tests => 556;  # Update this when adding/deleting tests.

 run_tests() unless caller;

@@ -1020,15 +1020,31 @@ sub run_tests {
 	ok("a" !~ /^(a)(??{ \$1 })/, '(??{ ref })');
     }

-    # make sure the uninit warning from returning an undef var
-    # sees the right var
+    # Make sure the uninit warning from returning an undef var
+    # in (??{...}) displays the right line and doesn't display
+    # the wrong var. In an ideal world it would display $u2 as the
+    # undef return value, but that information is no longer available,
+    # so displaying nothing is better than displaying something wrong
+    # like $u1. Similarly, the op being executed is no longer available.

     {
 	my ($u1, $u2);
-	my $warn = '';
-	local $SIG{__WARN__} = sub {  $warn .= $_[0] };
-	$u1 =~ /(??{$u2})/ or die;
-	like($warn, qr/value \$u1 in pattern match.*\n.*value at/, 'uninit');
+	my @warn;
+	local $SIG{__WARN__} = sub {  push @warn, $_[0]; };
+        my $l = __LINE__;
+        my $l1 = $l + 3;
+        my $l2 = $l + 6;
+	$u1 =~ /(??{
+                # padding to make final expression be on a different line
+                my $x = 1;
+                $u2;
+                })/ or die;
+	like($warn[0],
+             qr{uninitialized value \$u1 in pattern match \Q(m//)\E at .* line $l1},
+             'uninit1');
+	like($warn[1],
+             qr/uninitialized value at .* line $l2/,
+             'uninit2');
     }

     # test that code blocks are called in scalar context