From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30931 invoked by alias); 25 Mar 2002 21:26: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 30916 invoked by uid 71); 25 Mar 2002 21:26:02 -0000 Date: Mon, 25 Mar 2002 13:26:00 -0000 Message-ID: <20020325212602.30915.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Tom Tromey Subject: Re: java/5941: incorrect "Unreachable statement" error Reply-To: Tom Tromey X-SW-Source: 2002-03/txt/msg00944.txt.bz2 List-Id: The following reply was made to PR java/5941; it has been noted by GNATS. From: Tom Tromey To: shroff@transeda.com Cc: gcc-gnats@gcc.gnu.org, "Eric B. Blake" , Per Bothner Subject: Re: java/5941: incorrect "Unreachable statement" error Date: 25 Mar 2002 14:51:58 -0700 >>>>> "Saurin" == Saurin B Shroff writes: Hi. I looked at this PR a little more today. Saurin> Following is a simplified code that shows this behavior: In your original code the loop didn't appear to always complete abnormally. So this code looks different. We might be seeing two different problems. 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> return 12; 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. I think what gcj does is reasonable. This might simply be a bug in the language spec. However, I'm not certain. Perhaps there is a subtle reason for this omission. Eric, Per, what do you think? Saurin> What I would suggest that "Unreachable statement" should be a Saurin> warning rather than error since it stops the compilation The language specification requires an error for unreachable code. Tom