This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: java/5941: incorrect "Unreachable statement" error
- From: Eric Blake <ebb9 at email dot byu dot edu>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 2 Apr 2002 00:46:01 -0000
- Subject: Re: java/5941: incorrect "Unreachable statement" error
- Reply-to: Eric Blake <ebb9 at email dot byu dot edu>
The following reply was made to PR java/5941; it has been noted by GNATS.
From: Eric Blake <ebb9@email.byu.edu>
To: tromey@redhat.com
Cc: shroff@transeda.com, gcc-gnats@gcc.gnu.org,
Per Bothner <per@bothner.com>
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