diff options
author | Aaron Crane <arc@cpan.org> | 2016-05-08 18:13:30 +0100 |
---|---|---|
committer | Aaron Crane <arc@cpan.org> | 2016-05-09 13:30:25 +0100 |
commit | 51f69a247f06354aa055df45451b8b569803f561 (patch) | |
tree | 1b567e493d0ec2ed75e0065b5df76b4234f5fce4 /pp_hot.c | |
parent | 0f51bd1b04adcfb893439055d50b374d6eec71d0 (diff) | |
download | perl-51f69a247f06354aa055df45451b8b569803f561.tar.gz |
[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.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 { |