This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFA:] cpplib, c-opts: Don't warn on dollars in builtin macro definitions.
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: neil at daikokuya dot co dot uk
- Date: Thu, 12 Jun 2003 03:49:49 +0200
- Subject: [RFA:] cpplib, c-opts: Don't warn on dollars in builtin macro definitions.
Refer to the thread at
<URL:http://gcc.gnu.org/ml/gcc-bugs/2003-06/msg01231.html>. Patch
as outlined in that discussion with Neil. (There was pre-approval,
but for a different change with some misunderstanding involved,
so...)
Bootstrapped and tested (no Ada or treelang) on i686-pc-linux-gnu.
Built and tested on cris-axis-elf and cris-axis-linux-gnu, where it
fixes 6852 and 5746 regressions respectively. Built and tested on
cross to mmix-knuth-mmixware and m32r-unknown-elf, no regressions.
Ok to commit?
Don't warn on dollars in builtin macro definitions,
e.g. __REGISTER_PREFIX__.
* cpphash.h (struct cpp_reader): Move member warn_dollars...
* cpplib.h (struct cpp_options): ...to here. Change type to
unsigned char.
* cppinit.c (cpp_create_reader): Set it to 1 here.
(post_options): Don't set it here.
* c-opts.c (c_common_init_options): Reset it to 0 here.
(finish_options): Set it here.
* cpplex.c (forms_identifier_p): Tweak for new location of
warn_dollars.
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.187
diff -p -c -r1.187 cpphash.h
*** cpphash.h 17 May 2003 20:29:29 -0000 1.187
--- cpphash.h 11 Jun 2003 13:35:50 -0000
*************** struct cpp_reader
*** 378,387 ****
cpp_token avoid_paste;
cpp_token eof;
- /* True if we should warn about dollars in identifiers or numbers
- for this translation unit. */
- bool warn_dollars;
-
/* Opaque handle to the dependencies of mkdeps.c. */
struct deps *deps;
--- 378,383 ----
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.254
diff -p -c -r1.254 cpplib.h
*** cpplib.h 11 May 2003 13:43:35 -0000 1.254
--- cpplib.h 11 Jun 2003 13:35:51 -0000
*************** struct cpp_options
*** 300,305 ****
--- 300,309 ----
/* Zero means dollar signs are punctuation. */
unsigned char dollars_in_ident;
+ /* True if we should warn about dollars in identifiers or numbers
+ for this translation unit. */
+ unsigned char warn_dollars;
+
/* Nonzero means warn if undefined identifiers are evaluated in an #if. */
unsigned char warn_undef;
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.281
diff -p -c -r1.281 cppinit.c
*** cppinit.c 17 May 2003 20:29:30 -0000 1.281
--- cppinit.c 11 Jun 2003 13:35:51 -0000
*************** cpp_create_reader (lang, table)
*** 151,156 ****
--- 151,157 ----
CPP_OPTION (pfile, warn_deprecated) = 1;
CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
CPP_OPTION (pfile, dollars_in_ident) = 1;
+ CPP_OPTION (pfile, warn_dollars) = 1;
/* Default CPP arithmetic to something sensible for the host for the
benefit of dumb users like fix-header. */
*************** post_options (pfile)
*** 570,580 ****
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, warn_trigraphs) = 0;
}
-
- /* C99 permits implementation-defined characters in identifiers.
- The documented meaning of -std= is to turn off extensions that
- conflict with the specified standard, and since a strictly
- conforming program cannot contain a '$', we do not condition
- their acceptance on the -std= setting. */
- pfile->warn_dollars = CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99);
}
--- 571,574 ----
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.54
diff -p -c -r1.54 c-opts.c
*** c-opts.c 8 Jun 2003 07:54:10 -0000 1.54
--- c-opts.c 11 Jun 2003 13:35:52 -0000
*************** c_common_init_options (lang)
*** 225,230 ****
--- 225,235 ----
ident_hash);
cpp_opts = cpp_get_options (parse_in);
cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
+
+ /* Reset to avoid warnings on internal definitions. We set it just
+ before passing on command-line options to cpplib. */
+ cpp_opts->warn_dollars = 0;
+
if (flag_objc)
cpp_opts->objc = 1;
*************** finish_options ()
*** 1356,1361 ****
--- 1361,1378 ----
cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
cpp_init_builtins (parse_in, flag_hosted);
c_cpp_builtins (parse_in);
+
+ /* We're about to send user input to cpplib, so make it warn for
+ things that we previously (when we sent it internal definitions)
+ told it to not warn.
+
+ C99 permits implementation-defined characters in identifiers.
+ The documented meaning of -std= is to turn off extensions that
+ conflict with the specified standard, and since a strictly
+ conforming program cannot contain a '$', we do not condition
+ their acceptance on the -std= setting. */
+ cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99);
+
cpp_change_file (parse_in, LC_RENAME, _("<command line>"));
for (i = 0; i < deferred_count; i++)
{
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.235
diff -p -c -r1.235 cpplex.c
*** cpplex.c 17 May 2003 20:29:31 -0000 1.235
--- cpplex.c 11 Jun 2003 13:35:53 -0000
***************
*** 1,5 ****
/* CPP Library - lexical analysis.
! Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
--- 1,5 ----
/* CPP Library - lexical analysis.
! Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
*************** forms_identifier_p (pfile, first)
*** 402,410 ****
return false;
buffer->cur++;
! if (pfile->warn_dollars && !pfile->state.skipping)
{
! pfile->warn_dollars = false;
cpp_error (pfile, DL_PEDWARN, "'$' in identifier or number");
}
--- 402,410 ----
return false;
buffer->cur++;
! if (CPP_OPTION (pfile, warn_dollars) && !pfile->state.skipping)
{
! CPP_OPTION (pfile, warn_dollars) = 0;
cpp_error (pfile, DL_PEDWARN, "'$' in identifier or number");
}
brgds, H-P