develooper Front page | perl.perl5.porters | Postings from July 2001

[PATCH op.c] Dead code detection

Thread Next
From:
Simon Cozens
Date:
July 4, 2001 12:26
Subject:
[PATCH op.c] Dead code detection
Message ID:
20010704202603.A3765@deep-dark-truthful-mirror
Experimental. Warns about unconditional jumps followed by other statements.

--- op.c~	Wed Jul  4 10:43:48 2001
+++ op.c	Wed Jul  4 14:54:39 2001
@@ -6864,6 +6872,11 @@
 	    break;
 
 	case OP_EXEC:
+	case OP_REDO:
+	case OP_LAST:
+	case OP_GOTO:
+	case OP_NEXT:
+	case OP_RETURN:
 	    o->op_seq = PL_op_seqmax++;
 	    if (ckWARN(WARN_SYNTAX) && o->op_next
 		&& o->op_next->op_type == OP_NEXTSTATE) {
@@ -6876,8 +6889,9 @@
 		    CopLINE_set(PL_curcop, CopLINE((COP*)o->op_next));
 		    Perl_warner(aTHX_ WARN_EXEC,
 				"Statement unlikely to be reached");
-		    Perl_warner(aTHX_ WARN_EXEC,
-				"\t(Maybe you meant system() when you said exec()?)\n");
+		    if (o->op_type == OP_EXEC)
+			Perl_warner(aTHX_ WARN_EXEC,
+			"\t(Maybe you meant system() when you said exec()?)\n");
 		    CopLINE_set(PL_curcop, oldline);
 		}
 	    }
--- pod/perldiag.pod~	Wed Jul  4 20:23:15 2001
+++ pod/perldiag.pod	Wed Jul  4 20:25:09 2001
@@ -3228,11 +3228,13 @@
 
 =item Statement unlikely to be reached
 
-(W exec) You did an exec() with some statement after it other than a
-die().  This is almost always an error, because exec() never returns
-unless there was a failure.  You probably wanted to use system()
-instead, which does return.  To suppress this warning, put the exec() in
-a block by itself.
+(W exec) You did an exec() or some control statement with some statement
+after it. In the case of exec(), this is almost always an error, because
+exec() never returns unless there was a failure; you probably wanted to
+use system() instead, which does return, or follow the exec() with a
+die(). In the case of other control statements, an unconditional jump
+shouldn't be followed by other code, since that code can never be
+reached. To suppress this warning, put the statement in a block by itself.
 
 =item stat() on unopened filehandle %s
 

-- 
Overall there is a smell of fried onions.  (fnord)

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About