From: Rick Delaney Date: Wed, 13 Feb 2008 23:29:16 +0000 (-0500) Subject: Show constant in "Useless use of a constant in void context" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86f9315f71b1082772a0bd0036b997ad8e70748a;p=p5sagit%2Fp5-mst-13.2.git Show constant in "Useless use of a constant in void context" Message-ID: <20080214042916.GA12678@bort.ca> p4raw-id: //depot/perl@33305 --- diff --git a/op.c b/op.c index f38ce49..ff39198 100644 --- a/op.c +++ b/op.c @@ -1075,7 +1075,8 @@ Perl_scalarvoid(pTHX_ OP *o) no_bareword_allowed(o); else { if (ckWARN(WARN_VOID)) { - useless = "a constant"; + SV* msv = newSVpvf("a constant (%"SVf")", sv); + useless = SvPV_nolen(msv); 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 f0a6e62..edd2741 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -529,6 +529,8 @@ Useless use of a variable in void context at - line 6. use warnings 'void' ; "abc"; # OP_CONST 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; print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT @@ -536,9 +538,13 @@ $[ = 2; # should not warn no warnings 'void' ; "abc"; # OP_CONST 7 ; # OP_CONST +"x" . "y"; # optimized to OP_CONST +2 + 2; # optimized to OP_CONST EXPECT -Useless use of a constant in void context at - line 3. -Useless use of a constant in void context at - line 4. +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. ######## # op.c #