Bug 103192

Summary: gcj: compiler error with valid Java syntax.
Product: [Retired] Red Hat Linux Reporter: Tony Reix <tony.reix>
Component: gccAssignee: Tom Tromey <tromey>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 9CC: patrickm
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-08-28 14:42:34 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tony Reix 2003-08-27 16:10:34 UTC
Description of problem:

gcj refuses a syntax accepted by javac.

Factory.java: In class `spec.jbb.infra.Factory.Factory':
Factory.java: In method `spec.jbb.infra.Factory.Factory.tempArray
Near(int,int)':
Factory.java:300: error: Unreachable statement.
                case T_CHAR:

The following syntax is refused by gcj:
	switch (type) {
		case T_BOOLEAN:
                {
                    result = new boolean[entries];
                    break;
                };
                case T_CHAR:
                {
                    result = new char[entries];
                    break;
                };
	etc.

Removing the {} inside the case code fixes the problem.


Version-Release number of selected component (if applicable):

# cat /etc/redhat-release
Red Hat Linux release 9 (Shrike)  2.4.20-8smp

# gcj --version
gcj (GCC) 3.3.1


How reproducible:

Easy.


Steps to Reproduce:

Welcome.java :

public class Welcome
{

static final int T_BOOLEAN = 4;
static final int T_CHAR = 5;

        public static void main(String[] args)
        {
                System.out.println("You're welcome!");
                System.out.println();         
        }

        private static Object pb (int type)
        {
         Object result = null;

                switch (type)
                {
                        case T_BOOLEAN:
                        {
                        result = new boolean[1];
                        break;
                        };
                        case T_CHAR:
                        {
                        result = new char[2];
                        break;
                        };
                }
                return result;
        }
}

    
Actual results:

Compiler error message.


Expected results:

No compiler error message.

Additional info:

Comment 1 Tom Tromey 2003-08-28 14:42:34 UTC
This isn't a bug.  Change both instances of "};" to "}"
in the switch statement and this code will compile -- those
semicolons are invalid.

FWIW both jikes and Sun JDK 1.4.2 also reject this code.

Thanks for a very easy-to-reproduce bug report.  This is the
kind I like.


Comment 2 Tony Reix 2003-08-28 15:26:50 UTC
This code compiled perfectly well with IBM javac 1.1.8 and IBM javac 1.3.1.
I've tried now to compile it with IBM java 1.4.1 : yes that fails !
So it seems to be some uncompatibility between Java 1.4 and previous versions.
Thanks for help.

Comment 3 Tom Tromey 2003-08-28 16:01:10 UTC
Yeah, just FYI, older versions of javac tended
to be more lenient with regard to extraneous semicolons.
At one point we added code to gcj to let it do this
too, but I think we only added cases where we had
access to code causing problems for us.  In any case,
it is a deprecated feature of the compiler (both
standard and gcj) -- best to fix the code.