CPP fails to build in current CVS when using cc for stage1

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Wed Mar 8 09:14:00 GMT 2000


 > From: Zack Weinberg <zack@wolery.cumb.org>
 > 
 > On Tue, Mar 07, 2000 at 10:44:31PM -0500, Kaveh R. Ghazi wrote:
 > > Zack,
 > > 
 > > 	With current CVS, cpp fails to build on !GCC configurations.
 > > On alphaev5-dec-osf4.0b:
 > > 
 > >  > cc: Error: ../../egcs-CVS20000307/gcc/cppinit.c, line 941: In the
 > >  > 	static initialization, the address cannot be converted to the
 > >  > 	destination type.
 > >  > static const char no_arg[] = N_("Argument missing after `%s' option");
 > >  > -----------------------------^
 > 
 > Looks like N_() is being defined incorrectly.  intl.h has
 > 
 > #ifndef N_
 > # define N_(msgid) (msgid)
 > #endif
 > 
 > so if N_ is already defined somewhere, we'll get it wrong.  Can you
 > figure out what the bogus definition is and where it's coming from?


Okay, the definition I get for N_ is correct.  Each of the strings in
question resolves to ("string").  The problem is that the C compiler
on OSF4 is broken.

 > % cat foo.c
 > #include <stdio.h>
 > int main()
 > {
 > #ifdef ARRAY
 >   static const char foo[] = ("hello world\n");
 > #else
 >   static char *const foo = ("hello world\n");
 > #endif
 >   static const char *const bar = foo;
 >   
 >   printf (foo);
 >   return 0;
 > }
 > % cc -DARRAY foo.c
 > cc: Error: foo.c, line 5: In the static initialization, the address
 > 	cannot be converted to the destination type.
 >   static const char foo[] = ("hello world\n");
 > ----------------------------^
 > cc: Warning: foo.c, line 5: In the initializer for foo[0], "("hello world
 > ")" has a larger data size than "const signed char".  Assignment
 > 	may result in data loss.
 >   static const char foo[] = ("hello world\n");
 > ----------------------------^
 > cc: Warning: foo.c, line 5: In the initializer for foo[0], "("hello world
 > ")" of type "pointer to signed char", is being converted to "const signed char".
 >   static const char foo[] = ("hello world\n");
 > ----------------------------^

For some reason, cc gets confused by the parens around the string.  If
I remove the parens or if I change the char[] to a char*, it works.
The problem is that the char[] variables in cppinit.c are used as
static initializers further on down, and OSF4 cc chokes if I switch
them from char[] to char*.  This is what happens:

 > % cc foo.c
 > cc: Error: foo.c, line 9: In the initializer for bar, "foo" is not
 > 	constant, but occurs in a context that requires a constant
 > 	expression.
 >   static const char *const bar = foo;
 > ---------------------------------^

(Note gcc will also choke on a char* used as a static initializer.)

Since I didn't want to change intl.h to remove the parens and make
gcc's copy of it special, the only solution I could think of was to
make these strings macros instead.  I haven't done a full bootstrap
yet, just made sure OSF4 cc can compile all of stage1.

diff -rup orig/egcs-CVS20000307/gcc/cppinit.c egcs-CVS20000307/gcc/cppinit.c
--- orig/egcs-CVS20000307/gcc/cppinit.c	Tue Mar  7 18:21:55 2000
+++ egcs-CVS20000307/gcc/cppinit.c	Wed Mar  8 12:00:56 2000
@@ -938,12 +938,12 @@ struct cl_option
   enum opt_code opt_code;
 };
 
-static const char no_arg[] = N_("Argument missing after `%s' option");
-static const char no_ass[] = N_("Assertion missing after `%s' option");
-static const char no_dir[] = N_("Directory name missing after `%s' option");
-static const char no_fil[] = N_("File name missing after `%s' option");
-static const char no_mac[] = N_("Macro name missing after `%s' option");
-static const char no_pth[] = N_("Path name missing after `%s' option");
+#define no_arg N_("Argument missing after `%s' option")
+#define no_ass N_("Assertion missing after `%s' option")
+#define no_dir N_("Directory name missing after `%s' option")
+#define no_fil N_("File name missing after `%s' option")
+#define no_mac N_("Macro name missing after `%s' option")
+#define no_pth N_("Path name missing after `%s' option")
 
 /* This list must be ASCII sorted. Make enum order above match this. */
 #define DEF_OPT(text, msg, code) {text, msg, sizeof(text) - 1, code}
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


More information about the Gcc-bugs mailing list