From: Rafael Garcia-Suarez Date: Thu, 14 Feb 2008 15:14:36 +0000 (+0000) Subject: Make the new warning report undef constants as undef X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa01e09300100a2f35e7403a33b48963bfdcb712;p=p5sagit%2Fp5-mst-13.2.git Make the new warning report undef constants as undef p4raw-id: //depot/perl@33309 --- diff --git a/op.c b/op.c index ab5041f..3ec1979 100644 --- a/op.c +++ b/op.c @@ -1075,8 +1075,13 @@ Perl_scalarvoid(pTHX_ OP *o) no_bareword_allowed(o); else { if (ckWARN(WARN_VOID)) { - SV* msv = sv_2mortal(Perl_newSVpvf(aTHX_ "a constant (%"SVf")", sv)); - useless = SvPV_nolen(msv); + if (SvOK(sv)) { + SV* msv = sv_2mortal(Perl_newSVpvf(aTHX_ + "a constant (%"SVf")", sv)); + useless = SvPV_nolen(msv); + } + else + useless = "a constant (undef)"; if (o->op_private & OPpCONST_ARYBASE) useless = NULL; /* don't warn on optimised away booleans, eg diff --git a/t/lib/warnings/op b/t/lib/warnings/op index edd2741..9740e39 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -531,8 +531,9 @@ use warnings 'void' ; 7 ; # OP_CONST "x" . "y"; # optimized to OP_CONST 2 + 2; # optimized to OP_CONST -5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT use constant U => undef; +U; +5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT $[ = 2; # should not warn no warnings 'void' ; @@ -545,6 +546,7 @@ Useless use of a constant (abc) in void context at - line 3. Useless use of a constant (7) in void context at - line 4. Useless use of a constant (xy) in void context at - line 5. Useless use of a constant (4) in void context at - line 6. +Useless use of a constant (undef) in void context at - line 8. ######## # op.c #