This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [patch] Java definite assignment


On 6 Feb 2001, Per Bothner wrote:

> Mo DeJong <mdejong@cygnus.com> writes:
> 
> > tcltest::test non-const-1 { for + if with nonconst variable,
> >         this should fail since we can't know at compile time
> >         that b is true } {
> >     empty_main NC1 {
> >         int i;
> >         boolean b = true;
> >         for (;;) {
> >             if (b) {
> >                 i = 0;
> >                 break;
> >             }
> >         }
> >         i++;
> >     }
> > 
> > } FAIL
> 
> This should succeed.  The value of b is irrelevant.  The point
> is that *if* control reaches the i++, then we know that i has
> definitely been assigned to.  *Whether* control reaches the i++
> is a completely separate issue, a matter of unreachable
> statements, specified in a separate part of the JLS.

Well, here is a much more simple case of the same thing,
are you saying this code should compile because the if
statement can be reached and that the value of b does
not matter?

public class tmp {
    void foo() {
        int i;
        boolean b = false;
        if (b) {
            i = 0;
        }
        i++;
    
    }
}

GCJ currently errors out on this example:

% gcj -C tmp.java
tmp.java: In class `tmp':
tmp.java: In method `tmp.foo()':
tmp.java:8: Variable `i' may not have been initialized.
           i++;
   ^
1 error


So, which one is incorrect?

Mo DeJong
Red Hat Inc

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]