13 is(ref $rx, "Regexp", "qr// blessed into `Regexp' by default");
16 # Make sure /$qr/ doesn’t clobber match vars before the match (bug 70764).
23 $foo += () = ($a =~ /$rx/g);
24 $output .= "$foo\n"; # correct
27 for ($foo += ($a =~ /o/); $' && ($' =~ /o/) && ($foo++) ; ) { ; }
28 $output .= "1: $foo\n"; # No error
31 for ($foo += ($a =~ /$rx/); $' && ($' =~ /$rx/) && ($foo++) ; ) { ; }
32 $output .= "2: $foo\n"; # initialization warning, incorrect results
34 is $output, "5\n1: 5\n2: 5\n", '$a_match_var =~ /$qr/';
42 $foo += () = ($a =~ /$rx/g);
43 $output .= "$foo\n"; # correct
46 for ($foo += ($a =~ /o/); $' && /o/ && ($foo++) ; ) { ; }
47 $output .= "1: $foo\n"; # No error
50 for ($foo += ($a =~ /$rx/); $' && /$rx/ && ($foo++) ; ) { ; }
51 $output .= "2: $foo\n"; # initialization warning, incorrect results
53 is $output, "5\n1: 5\n2: 5\n", '/$qr/ with my $_ aliased to a match var';
61 $foo += () = ($a =~ /$rx/g);
62 $output .= "$foo\n"; # correct
65 for ($foo += ($a =~ /o/); $' && /o/ && ($foo++) ; ) { ; }
66 $output .= "1: $foo\n"; # No error
69 for ($foo += ($a =~ /$rx/); $' && /$rx/ && ($foo++) ; ) { ; }
70 $output .= "2: $foo\n"; # initialization warning, incorrect results
72 is $output, "5\n1: 5\n2: 5\n", q|/$qr/ with $'_ aliased to a match var|;
75 # Make sure /$qr/ calls get-magic on its LHS (bug 71470).
78 sub qrBug::TIESCALAR{bless[], 'qrBug'}
79 sub qrBug::FETCH { $scratch .= "[fetching]"; 'glat' }
80 tie my $flile, "qrBug";
82 is $scratch, "[fetching]", '/$qr/ with magical LHS';
86 # [perl 72922]: A 'copy' of a Regex object which has magic should not crash
87 # When a Regex object was copied and the copy weaken then the original regex object
88 # could no longer be 'copied' with qr//
90 my $prog = tempfile();
91 open my $fh, ">", $prog or die "Can't write to tempfile";
95 use Scalar::Util 'weaken';
99 my $re_weak_copy = $re;;
100 weaken($re_weak_copy);
101 my $re_copy2 = qr/$re/;
104 is("$$re_weak_copy", $str_re, "weak copy equals original");
105 is("$re_copy1", $str_re, "copy1 equals original");
106 is("$re_copy2", $str_re, "copy2 equals original");
108 my $refcnt_start = Internals::SvREFCNT($$re_weak_copy);
111 is(Internals::SvREFCNT($$re_weak_copy), $refcnt_start - 1, "refcnt decreased");
112 is("$re_weak_copy", $str_re, "weak copy still equals original");
115 is(Internals::SvREFCNT($$re_weak_copy), $refcnt_start - 1, "refcnt not decreased");
116 is("$re_weak_copy", $str_re, "weak copy still equals original");
123 my $out = runperl(stderr => 1, progfile => $prog);
126 my $expected = <<'EOOUT';
127 ok 1 - weak copy equals original
128 ok 2 - copy1 equals original
129 ok 3 - copy2 equals original
130 ok 4 - refcnt decreased
131 ok 5 - weak copy still equals original
132 ok 6 - refcnt not decreased
133 ok 7 - weak copy still equals original
134 ok 8 - weak copy equals original
135 ok 9 - copy1 equals original
136 ok 10 - copy2 equals original
137 ok 11 - refcnt decreased
138 ok 12 - weak copy still equals original
139 ok 13 - refcnt not decreased
140 ok 14 - weak copy still equals original
143 is ($out, $expected, '[perl #72922] copy of a regex of which a weak copy exist');