From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26012 invoked by alias); 2 Apr 2002 00:46:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 25947 invoked by uid 71); 2 Apr 2002 00:46:01 -0000 Date: Mon, 01 Apr 2002 16:46:00 -0000 Message-ID: <20020402004601.25946.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Eric Blake Subject: Re: java/5941: incorrect "Unreachable statement" error Reply-To: Eric Blake X-SW-Source: 2002-04/txt/msg00019.txt.bz2 List-Id: The following reply was made to PR java/5941; it has been noted by GNATS. From: Eric Blake To: tromey@redhat.com Cc: shroff@transeda.com, gcc-gnats@gcc.gnu.org, Per Bothner Subject: Re: java/5941: incorrect "Unreachable statement" error Date: Mon, 01 Apr 2002 17:42:18 -0700 I finally received a reply from Neal Gafter, one of Sun's engineers, offline. To summarize his position (as I don't think I am allowed to quote it): for (int i = 0; ; i++) break; is legal, even though i++ will never be executed, because i++ is not a complete statement and is therefore not subject to the rules of JLS 14.20. In fact, this next program should be legal as well, based on the definite assignment rules for For statements in JLS chapter 16. Note that Sun's JDK 1.3 and 1.4 does not compile it, it has been recorded as Sun bug 4660984; Jikes also fails this example, jikes bug 2780: class C { void bar() { for (final int i; 0 < (i = 1); i = i + 1) break; } } Tom Tromey wrote: > > > Saurin> public class bug2 { > Saurin> public static int showBug2 () { > Saurin> for (int i=0; i <= 10; i++) { > Saurin> if ( i > 3 ) { > Saurin> return 10; > Saurin> } else { > Saurin> return 11; > Saurin> } > Saurin> } > Saurin> } > Saurin> } > > Saurin> As you will notice that loop is exited after first iteration, > Saurin> and so the loop incrementer "i++" will never be executed. > > Yes. It looks like the language spec is unclear on this issue. > > I'm looking at The Java Language Specification, 2nd Edition. Section > 14.20 deals with unreachable statements. The subsection on the `for' > statement doesn't mention conditions under which the update expression > is considered unreachable. > > The Sun JDK 1.2 and 1.4 `javac' compilers don't give an error here, > which is suggestive but not authoritative. -- This signature intentionally left boring. Eric Blake ebb9@email.byu.edu BYU student, free software programmer