Skip to content

Commit

Permalink
undef $0 shouldn't warn about $0
Browse files Browse the repository at this point in the history
RT #123910

    $ perl -we'undef $0'
    Use of uninitialized value $0 in undef operator at -e line 1.

Generally, undef should ignore its arg when determining which var was
undef: only magic will trigger an undef warning.
  • Loading branch information
iabyn committed Sep 28, 2016
1 parent 81b96c3 commit 614f2ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -15823,6 +15823,11 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,

switch (obase->op_type) {

case OP_UNDEF:
/* undef should care if its args are undef - any warnings
* will be from tied/magic vars */
break;

case OP_RV2AV:
case OP_RV2HV:
case OP_PADAV:
Expand Down Expand Up @@ -16369,7 +16374,6 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
case OP_ALARM:
case OP_SEMGET:
case OP_GETLOGIN:
case OP_UNDEF:
case OP_SUBSTR:
case OP_AEACH:
case OP_EACH:
Expand Down
8 changes: 8 additions & 0 deletions t/lib/warnings/9uninit
Original file line number Diff line number Diff line change
Expand Up @@ -2186,3 +2186,11 @@ use warnings 'uninitialized';
my $x = "" . open my $fh, "<", "no / such / file";
EXPECT
Use of uninitialized value in concatenation (.) or string at - line 3.
########
# RT #123910
# undef's arg being undef doesn't trigger warnings - any warning will be
# from tied/magic vars
use warnings 'uninitialized';
undef $0;
EXPECT
Use of uninitialized value in undef operator at - line 5.

0 comments on commit 614f2ce

Please sign in to comment.