This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #127877] Emit undef warning on sassign+concat
authorAaron Crane <arc@cpan.org>
Sun, 8 May 2016 17:13:30 +0000 (18:13 +0100)
committerAaron Crane <arc@cpan.org>
Mon, 9 May 2016 12:30:25 +0000 (13:30 +0100)
commit51f69a247f06354aa055df45451b8b569803f561
tree1b567e493d0ec2ed75e0065b5df76b4234f5fce4
parent0f51bd1b04adcfb893439055d50b374d6eec71d0
[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.
pp_hot.c
t/lib/warnings/9uninit