Bug 8298 - Incomplete enforcement of constant expressions in switch/case
Summary: Incomplete enforcement of constant expressions in switch/case
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on: 28067
Blocks:
  Show dependency treegraph
 
Reported: 2002-10-21 00:56 UTC by mcmartin
Modified: 2007-01-09 20:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-30 13:35:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mcmartin 2002-10-21 00:56:00 UTC
The GCJ front-end should reject this, as the cases y.a and y.b don't match the definition of ConstantExpression in section 15.28 of the JLS (as required for cases in a switch in section 14.10 of the JLS):

public class test {
    static final int a = 1;
    static final int b = 2;

    public static void main(String[] args) {
	int x = 2;
	test y = new test();
	switch(x) {
	case y.a:
	    System.out.println("Equal to a");
	    break;
	case y.b:
	    System.out.println("Equal to b");
	    break;
	default:
	    System.out.println("Something random");
	    break;
	}
    }
}

Release:
gcj 3.2
Comment 1 Andrew Pinski 2003-05-23 22:24:24 UTC
still happens on mainline (20030523).
Comment 2 Tom Tromey 2007-01-09 20:44:05 UTC
All gcj front end bugs have been fixed by the gcj-eclipse branch merge.
I'm mass-closing the affected PRs.
If you believe one of these was closed in error, please reopen it
with a note explaining why.
Thanks.