Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!clyde!watmath!rbutterworth From: rbutterworth@watmath.UUCP (Ray Butterworth) Newsgroups: comp.bugs.4bsd Subject: yacc grammar for LINT. Message-ID: <3436@watmath.UUCP> Date: Thu, 20-Nov-86 11:52:27 EST Article-I.D.: watmath.3436 Posted: Thu Nov 20 11:52:27 1986 Date-Received: Fri, 21-Nov-86 00:51:21 EST Distribution: comp Organization: U of Waterloo, Ontario Lines: 27 Consider the following contrived example: func(x) { if (x) return 0; if (!x) exit(1); /*NOTREACHED*/ return; } Even if LINT doesn't know that exit() never returns, the NOTREACHED should tell it. It should complain that the second return is never executed. In fact the NOTREACHED is totally ignored. Putting a ";" before the NOTREACHED makes LINT behave correctly though. What is happening is that in parsing the "if (!x) exit(1);", yacc has to read ahead to make sure there isn't an "else" to go with the "if". It processes the /*NOTREACHED*/ at this point and zeros the "reached" flag, but there isn't an "else" so the statement is considered to be complete at the semicolon after the exit and everything is cleaned up for the end of a statement and the "reached" flag is set to 1 again. Now it tries to parse the next line, but the /*NOTREACHED*/ has already gone, so the next thing it sees is the "return" and since "reached" is set it doesn't realize that this code is never executed. Anyone know how to fix this? (The yacc source that is, not my stupid example.)