[perl #119501] \(1+2) always referencing the same sv
authorFather Chrysostomos <sprout@cpan.org>
Tue, 17 Sep 2013 15:26:12 +0000 (08:26 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 17 Sep 2013 15:32:09 +0000 (08:32 -0700)
commitacb3405042618ee03217199647b0b92863b95088
treeac1c5fbc0d5860875d88a5042628bd02a99684e4
parentccfc25677a64918883e67e4f4942fa0fb5556bfc
[perl #119501] \(1+2) always referencing the same sv

2484f8dbbb hid the fact that constant folding happens by making 1+2
fold to  a PADTMP, an SV that is never used as an lvalue and gets cop-
ied if one tries to use it that way.

The PADTMP mechanism is what allows \"$x" to return a new value each
time, even though ops like "$x" actually reuse the same scalar repeat-
edly to return values.

Because \ copies PADTMPs, \(1+2) ends up folding 1+2 to 3 (marked
PADTMP), which is then copied by the \ at compile time.  (Constant
folding works by evaluating certain ops at compile time and then
inlining their returned value.)  The result is that we have a folded
\3 where 3 is *not* marked PADTMP (the reference is, instead); hence
\(1+2) gives the same scalar each time, producing a value that can be
modified, affecting future evaluations.

The solution is to skip folding \ if its argument is a PADTMP.
op.c
t/comp/fold.t