This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
(perl #129125) copy form data if it might be freed
[perl5.git] / t / op / magic-27839.t
1 #!./perl -w
2
3 BEGIN {
4     $SIG{__WARN__} = sub { die "Dying on warning: ", @_ };
5     chdir 't' if -d 't';
6     require './test.pl';
7     skip_all_if_miniperl(
8         "no dynamic loading on miniperl, no Tie::Hash::NamedCapture"
9     );
10 }
11
12 plan(tests => 2);
13
14 use strict;
15
16 # Test for bug [perl #27839]
17 {
18     my $x;
19     sub f {
20         "abc" =~ /(.)./;
21         $x = "@+";
22         return @+;
23     };
24     "pqrstuvwxyz" =~ /..(....)../; # prime @+ etc in this scope
25     my @y = f();
26     is $x, "@y", "return a magic array ($x) vs (@y)";
27
28     sub f2 {
29         "abc" =~ /(?<foo>.)./;
30         my @h =  %+;
31         $x = "@h";
32         return %+;
33     };
34     @y = f();
35     is $x, "@y", "return a magic hash ($x) vs (@y)";
36 }
37