From 78b8811a387bd5f91d4b0a70fdd63e043ffa4bf9 Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson <hp@axis.com> Date: Thu, 12 Jun 2003 06:09:15 +0000 Subject: [PATCH] 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. From-SVN: r67824 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/c-opts.c | 17 +++++++++++++++++ gcc/cpphash.h | 4 ---- gcc/cppinit.c | 8 +------- gcc/cpplex.c | 6 +++--- gcc/cpplib.h | 4 ++++ 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f23fe499c931..1e9547180885 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2003-06-12 Hans-Peter Nilsson <hp@axis.com> + + 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. + 2003-06-11 Uwe Stieber <uwe@kaos-group.de> * config.gcc (arm*-*-kaos*, i[34567]86-*-kaos*, powerpc-*-kaos*, diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 43057ab551ca..6f449a00bb34 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -225,6 +225,11 @@ c_common_init_options (lang) 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; @@ -1356,6 +1361,18 @@ finish_options () 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++) { diff --git a/gcc/cpphash.h b/gcc/cpphash.h index aa5eec4e9d44..88addeac4d5c 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -378,10 +378,6 @@ struct cpp_reader 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; diff --git a/gcc/cppinit.c b/gcc/cppinit.c index d6e7ae426d2e..cace8b9f5db9 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -151,6 +151,7 @@ cpp_create_reader (lang, table) 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. */ @@ -570,11 +571,4 @@ post_options (pfile) 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); } diff --git a/gcc/cpplex.c b/gcc/cpplex.c index a79bedd154db..e072f01bdcf0 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -1,5 +1,5 @@ /* CPP Library - lexical analysis. - Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. + 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 @@ -402,9 +402,9 @@ forms_identifier_p (pfile, first) return false; buffer->cur++; - if (pfile->warn_dollars && !pfile->state.skipping) + if (CPP_OPTION (pfile, warn_dollars) && !pfile->state.skipping) { - pfile->warn_dollars = false; + CPP_OPTION (pfile, warn_dollars) = 0; cpp_error (pfile, DL_PEDWARN, "'$' in identifier or number"); } diff --git a/gcc/cpplib.h b/gcc/cpplib.h index a47a7fbf077f..45142527ea20 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -300,6 +300,10 @@ struct cpp_options /* 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; -- GitLab