summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorAaron Crane <arc@cpan.org>2016-05-08 18:13:30 +0100
committerAaron Crane <arc@cpan.org>2016-05-09 13:30:25 +0100
commit51f69a247f06354aa055df45451b8b569803f561 (patch)
tree1b567e493d0ec2ed75e0065b5df76b4234f5fce4 /pp_hot.c
parent0f51bd1b04adcfb893439055d50b374d6eec71d0 (diff)
downloadperl-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.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/pp_hot.c b/pp_hot.c
index d6cb1aa091..223169bd53 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 {