summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-04-06 17:43:29 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-04-06 20:27:22 -0700
commit4c3ac4ba94c3963cbfea8fd6a28648d68ac6063a (patch)
tree24a7c6b8d79ee9d137ef2e0179bf41754c8ad784
parent150b625d31233719d0d078c7d9ebe5ac46a6c4da (diff)
downloadperl-4c3ac4ba94c3963cbfea8fd6a28648d68ac6063a.tar.gz
[perl #87708] $tied + $tied
This is just part of #87708. This fixes the + operator outside of any ‘use integer’ when the same tied scalar is used for both operands and returns two different val- ues. Before this commit, get-magic would be called only once and the same value used. In 5.12.x it worked.
-rw-r--r--pp_hot.c10
-rw-r--r--t/lib/warnings/9uninit10
-rw-r--r--t/op/tie_fetch_count.t2
3 files changed, 21 insertions, 1 deletions
diff --git a/pp_hot.c b/pp_hot.c
index f8a61cbdb2..3d46287c7a 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -501,6 +501,16 @@ PP(pp_add)
svl = TOPm1s;
useleft = USE_LEFT(svl);
+ if(useleft && svr == svl) {
+ /* Print the uninitialized warning now, so it includes the vari-
+ able name. */
+ if (!SvOK(svl)) report_uninit(svl), useleft = 0;
+ /* Non-magical sv_mortalcopy */
+ svl = sv_newmortal();
+ sv_setsv_flags(svl, svr, 0);
+ SvGETMAGIC(svr);
+ }
+
#ifdef PERL_PRESERVE_IVUV
/* We must see if we can perform the addition with integers if possible,
as the integer code detects overflow while the NV code doesn't.
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit
index a16fd35528..33cc2b9080 100644
--- a/t/lib/warnings/9uninit
+++ b/t/lib/warnings/9uninit
@@ -689,6 +689,16 @@ Use of uninitialized value $g1 in subtraction (-) at - line 20.
Use of uninitialized value $m1 in subtraction (-) at - line 20.
########
use warnings 'uninitialized';
+sub TIESCALAR{bless[]}
+sub FETCH { undef }
+
+tie my $m1, "";
+my $v = $m1 + $m1;
+EXPECT
+Use of uninitialized value $m1 in addition (+) at - line 6.
+Use of uninitialized value $m1 in addition (+) at - line 6.
+########
+use warnings 'uninitialized';
my ($m1, $v);
our ($g1);
diff --git a/t/op/tie_fetch_count.t b/t/op/tie_fetch_count.t
index d6cf9c61cc..be339cdc3f 100644
--- a/t/op/tie_fetch_count.t
+++ b/t/op/tie_fetch_count.t
@@ -228,8 +228,8 @@ bin_test '.' , 1, 2, 12;
{
local $TODO = $todo ;
bin_test '==', 1, 2, "";
- bin_test '+' , 1, 2, 3;
}
+bin_test '+' , 1, 2, 3;
bin_int_test '*' , 2, 3, 6;
bin_int_test '/' , 10, 2, 5;
bin_int_test '%' , 11, 2, 1;