From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8011 invoked by alias); 23 Nov 2005 14:07:36 -0000 Received: (qmail 7988 invoked by uid 48); 23 Nov 2005 14:07:35 -0000 Date: Wed, 23 Nov 2005 14:07:00 -0000 Subject: [Bug java/25001] New: dos equis X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: java-prs@gcc.gnu.org From: "vadimn at redhat dot com" Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org X-SW-Source: 2005-q4/txt/msg00388.txt.bz2 List-Id: GCJ produces incorrect byte- and native code for a variation of 2-expressive-puzzlers/puzzle-8/DosEquis.java from http://www.javapuzzlers.com/java-puzzlers.zip Specifically, | $ cat DosEquis.java | public class DosEquis { | public static void main(String[] _) { | char x = 'X'; | final int i = 0; | System.out.print (true ? x : 0); | System.out.println(false ? i : x); | } | } This should print out XX, as it does under Sun's JVM: | $ java -version | java version "1.4.2_08" | Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03) | Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode) | $ javac DosEquis.java | $ java -cp . DosEquis | XX Under GCJ, I get X88 instead: | $ gcj --version | gcj (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5) | Copyright (C) 2005 Free Software Foundation, Inc. | This is free software; see the source for copying conditions. There is NO | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | $ gcj -C DosEquis.java | $ gij DosEquis | X88 | $ gcj -o dos-equis --main=DosEquis DosEquis.java | $ ./dos-equis | X88 Eclipse compiler gets it right: | $ rm DosEquis.class | $ ecj -v | Eclipse Java Compiler v_579_R31x, 3.1.1 release, Copyright IBM Corp \ | 2000, 2005. All rights reserved. | $ ecj DosEquis.java | $ gij DosEquis | XX GCJ violates the following JLS clause: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#290293 | 15.25 Conditional Operator ? : | | The type of a conditional expression is determined as follows: | | * If one of the operands is of type T where T is byte, short, or | char, and the other operand is a constant expression of type int | whose value is representable in type T, then the type of the | conditional expression is T. Since i is declared final in the above example, it is a constant expression of type int. Therefore, the above clause applies in this case. -- Summary: dos equis Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vadimn at redhat dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25001