This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Only warn about "Statement unlikely to be reached" after an exec if exec is a statement.
authorGerard Goossen <gerard@ggoossen.net>
Mon, 8 Aug 2011 20:18:03 +0000 (22:18 +0200)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 8 Aug 2011 22:54:48 +0000 (15:54 -0700)
Moving the OP_EXEC check to finalize_optree changed that it would also
warn if 'exec' is part of an expression. This patch changes the
behaviour to only warn if 'exec' is the whole statement, which
appears to be the behaviour before moving the check to finalize_optree.

op.c
t/lib/warnings/op

diff --git a/op.c b/op.c
index f862cd8..d20009e 100644 (file)
--- a/op.c
+++ b/op.c
@@ -1445,14 +1445,15 @@ S_finalize_op(pTHX_ OP* o)
        PL_curcop = ((COP*)o);          /* for warnings */
        break;
     case OP_EXEC:
-       if (o->op_next && o->op_next->op_type == OP_NEXTSTATE
+       if ( o->op_sibling
+           && (o->op_sibling->op_type == OP_NEXTSTATE || o->op_sibling->op_type == OP_DBSTATE)
            && ckWARN(WARN_SYNTAX))
            {
-               if (o->op_next->op_sibling) {
-                   const OPCODE type = o->op_next->op_sibling->op_type;
+               if (o->op_sibling->op_sibling) {
+                   const OPCODE type = o->op_sibling->op_sibling->op_type;
                    if (type != OP_EXIT && type != OP_WARN && type != OP_DIE) {
                        const line_t oldline = CopLINE(PL_curcop);
-                       CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
+                       CopLINE_set(PL_curcop, CopLINE((COP*)o->op_sibling));
                        Perl_warner(aTHX_ packWARN(WARN_EXEC),
                            "Statement unlikely to be reached");
                        Perl_warner(aTHX_ packWARN(WARN_EXEC),
index e596e79..b3cb7d6 100644 (file)
@@ -755,6 +755,12 @@ EXPECT
 Statement unlikely to be reached at - line 4.
        (Maybe you meant system() when you said exec()?)
 ########
+# op.c, no warning if exec isn't a statement.
+use warnings 'syntax' ;
+$a || exec "$^X -e 1" ;
+my $a
+EXPECT
+########
 # op.c
 my @a; defined(@a);
 EXPECT