In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/51f69a247f06354aa055df45451b8b569803f561?hp=0f51bd1b04adcfb893439055d50b374d6eec71d0>

- Log -----------------------------------------------------------------
commit 51f69a247f06354aa055df45451b8b569803f561
Author: Aaron Crane <[email protected]>
Date:   Sun May 8 18:13:30 2016 +0100

    [perl #127877] Emit undef warning on sassign+concat
    
    Code like this:
    
        my $x;
        $x .= 'a';
    
    is specifically exempted from "use of uninitialized value" warnings,
    according to the "Declarations" section of perlsyn, to allow the idiom of
    building up a value piecemeal. The same is true of the += and -= operators.
    However, breaking the combined assignment up into the underlying operator
    and a simple assignment, as in this code:
    
        my $x;
        $x = $x . 'a';
    
    *should* produce a warning.
    
    That warning was correctly being emitted for addition and subtraction, but
    concatenation was behaving as the ".=" case, because "$x = $x . EXPR" is
    optimized to the equivalent of "$x .= EXPR".
    
    So we now explicitly detect this case, and emit the desired warning.
-----------------------------------------------------------------------

Summary of changes:
 pp_hot.c               |  7 +++++--
 t/lib/warnings/9uninit | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/pp_hot.c b/pp_hot.c
index d6cb1aa..223169b 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -284,8 +284,11 @@ PP(pp_concat)
     }
     else { /* $l .= $r   and   left == TARG */
        if (!SvOK(left)) {
-           if (left == right && ckWARN(WARN_UNINITIALIZED)) /* $l .= $l */
-               report_uninit(right);
+            if ((left == right                          /* $l .= $l */
+                 || (PL_op->op_private & OPpTARGET_MY)) /* $l = $l . $r */
+                && ckWARN(WARN_UNINITIALIZED)
+                )
+                report_uninit(left);
            sv_setpvs(left, "");
        }
         else {
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit
index ef9b4f6..42915d9 100644
--- a/t/lib/warnings/9uninit
+++ b/t/lib/warnings/9uninit
@@ -2138,3 +2138,24 @@ Use of uninitialized value $i in array element at - line 
12.
 Use of uninitialized value $k in hash element at - line 12.
 Use of uninitialized value $i in array element at - line 13.
 Use of uninitialized value $k in hash element at - line 13.
+########
+# perl #127877
+use warnings 'uninitialized';
+my ($p, $q, $r, $s, $t, $u, $v, $w, $x, $y);
+$p = $p . "a";
+$q .= "a";
+$r = $r + 17;
+$s += 17;
+$t = $t - 17;
+$u -= 17;
+use integer;
+$v = $v + 17;
+$w += 17;
+$x = $x - 17;
+$y -= 17;
+EXPECT
+Use of uninitialized value $p in concatenation (.) or string at - line 4.
+Use of uninitialized value $r in addition (+) at - line 6.
+Use of uninitialized value $t in subtraction (-) at - line 8.
+Use of uninitialized value $v in integer addition (+) at - line 11.
+Use of uninitialized value $x in integer subtraction (-) at - line 13.

--
Perl5 Master Repository

Reply via email to