This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Deal with gjavah oddity
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 31 Jan 2005 22:59:41 -0800
- Subject: C++ PATCH: Deal with gjavah oddity
- Reply-to: mark at codesourcery dot com
As Ranjit discovered, gjavah is generating invalid C++ code: in-class
initializations of static data members of floating-point type.
Presumably, these should be changed into out-of-class
initializations. But, I didn't want to take risks, so I just made
G++ complain only if pedantic, and then had gjavah mark the
declarations with __extension__. Tested by building libjava on
x86_64-unknown-linux-gnu, applied on the mainline.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-01-31 Mark Mitchell <mark@codesourcery.com>
* parser.c (cp_parser_primary_expression): Don't complain about
floating-point literals in integral constant expressions when
!pedantic.
2005-01-31 Mark Mitchell <mark@codesourcery.com>
* gjavah.c (print_field_info): Mark static data members of
floating-point type with "__extension__".
Index: java/gjavah.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/gjavah.c,v
retrieving revision 1.124
diff -c -5 -p -r1.124 gjavah.c
*** java/gjavah.c 25 Nov 2004 11:13:37 -0000 1.124
--- java/gjavah.c 1 Feb 2005 06:54:54 -0000
*************** print_field_info (FILE *stream, JCF* jcf
*** 766,777 ****
print_field_name (stream, jcf, name_index, 0);
fputs ("\n", stream);
print_cxx_classname (stream, "#define ", jcf, jcf->this_class, 1);
fputs ("_", stream);
}
- else
- fputs ("static ", stream);
if ((flags & ACC_FINAL) && current_field_value > 0)
{
char buffer[25];
int done = 1;
--- 766,775 ----
*************** print_field_info (FILE *stream, JCF* jcf
*** 781,791 ****
case CONSTANT_Integer:
{
jint num;
int most_negative = 0;
if (! flag_jni)
! fputs ("const jint ", stream);
print_field_name (stream, jcf, name_index, 0);
fputs (flag_jni ? " " : " = ", stream);
num = JPOOL_INT (jcf, current_field_value);
/* We single out the most negative number to print
specially. This avoids later warnings from g++. */
--- 779,789 ----
case CONSTANT_Integer:
{
jint num;
int most_negative = 0;
if (! flag_jni)
! fputs ("static const jint ", stream);
print_field_name (stream, jcf, name_index, 0);
fputs (flag_jni ? " " : " = ", stream);
num = JPOOL_INT (jcf, current_field_value);
/* We single out the most negative number to print
specially. This avoids later warnings from g++. */
*************** print_field_info (FILE *stream, JCF* jcf
*** 803,813 ****
case CONSTANT_Long:
{
jlong num;
int most_negative = 0;
if (! flag_jni)
! fputs ("const jlong ", stream);
print_field_name (stream, jcf, name_index, 0);
fputs (flag_jni ? " " : " = ", stream);
num = JPOOL_LONG (jcf, current_field_value);
/* We single out the most negative number to print
specially.. This avoids later warnings from g++. */
--- 801,811 ----
case CONSTANT_Long:
{
jlong num;
int most_negative = 0;
if (! flag_jni)
! fputs ("static const jlong ", stream);
print_field_name (stream, jcf, name_index, 0);
fputs (flag_jni ? " " : " = ", stream);
num = JPOOL_LONG (jcf, current_field_value);
/* We single out the most negative number to print
specially.. This avoids later warnings from g++. */
*************** print_field_info (FILE *stream, JCF* jcf
*** 824,843 ****
break;
case CONSTANT_Float:
{
jfloat fnum = JPOOL_FLOAT (jcf, current_field_value);
if (! flag_jni)
! fputs ("const jfloat ", stream);
print_field_name (stream, jcf, name_index, 0);
jni_print_float (stream, fnum);
}
break;
case CONSTANT_Double:
{
jdouble dnum = JPOOL_DOUBLE (jcf, current_field_value);
if (! flag_jni)
! fputs ("const jdouble ", stream);
print_field_name (stream, jcf, name_index, 0);
jni_print_double (stream, dnum);
}
break;
default:
--- 822,849 ----
break;
case CONSTANT_Float:
{
jfloat fnum = JPOOL_FLOAT (jcf, current_field_value);
if (! flag_jni)
! /* ISO C++ does not allow initialization of a static
! data member of floating-point type. Thus, this
! code is making use of an undocumented GNU C++
! extension. */
! fputs ("__extension__ static const jfloat ", stream);
print_field_name (stream, jcf, name_index, 0);
jni_print_float (stream, fnum);
}
break;
case CONSTANT_Double:
{
jdouble dnum = JPOOL_DOUBLE (jcf, current_field_value);
if (! flag_jni)
! /* ISO C++ does not allow initialization of a static
! data member of floating-point type. Thus, this
! code is making use of an undocumented GNU C++
! extension. */
! fputs ("__extension__ static const jdouble ", stream);
print_field_name (stream, jcf, name_index, 0);
jni_print_double (stream, dnum);
}
break;
default:
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.306
diff -c -5 -p -r1.306 parser.c
*** cp/parser.c 1 Feb 2005 01:01:25 -0000 1.306
--- cp/parser.c 1 Feb 2005 06:54:55 -0000
*************** cp_parser_primary_expression (cp_parser
*** 2680,2690 ****
token = cp_lexer_consume_token (parser->lexer);
/* Floating-point literals are only allowed in an integral
constant expression if they are cast to an integral or
enumeration type. */
if (TREE_CODE (token->value) == REAL_CST
! && parser->integral_constant_expression_p)
{
/* CAST_P will be set even in invalid code like "int(2.7 +
...)". Therefore, we have to check that the next token
is sure to end the cast. */
if (cast_p)
--- 2680,2691 ----
token = cp_lexer_consume_token (parser->lexer);
/* Floating-point literals are only allowed in an integral
constant expression if they are cast to an integral or
enumeration type. */
if (TREE_CODE (token->value) == REAL_CST
! && parser->integral_constant_expression_p
! && pedantic)
{
/* CAST_P will be set even in invalid code like "int(2.7 +
...)". Therefore, we have to check that the next token
is sure to end the cast. */
if (cast_p)