diff options
author | Neil Booth <neil@daikokuya.co.uk> | 2003-05-17 20:29:34 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2003-05-17 20:29:34 +0000 |
commit | b1822ccc44ac015fac2558ca151fa6154bd66880 (patch) | |
tree | cc833b5eaad739137055c876d152a481427bc136 /gcc | |
parent | a69e127ba7e8e92dee6620fd692672955247b51b (diff) | |
download | gcc-b1822ccc44ac015fac2558ca151fa6154bd66880.zip gcc-b1822ccc44ac015fac2558ca151fa6154bd66880.tar.gz gcc-b1822ccc44ac015fac2558ca151fa6154bd66880.tar.bz2 |
c-common.c, c-common.h (dollars_in_ident): Remove.
* c-common.c, c-common.h (dollars_in_ident): Remove.
* c-opts.c (DOLLARS_IN_IDENTIFIERS): Default to true.
(c_common_init_options, c_common_decode_option): Set dollars_in_ident.
* cpphash.h (warned_dollar): Rename warn_dollars.
* cppinit.c (struct lang_flags, lang_defaults, cpp_set_lang)
Permit dollars regardless of -std=.
(post_options): Set warn_dollars.
* cpplex.c (forms_identifier_p): Use warn_dollars.
* config/darwin.h, config/alpha/vms.h, config/m68hc11/m68hc11.h:
Remove redundant definitions of DOLLARS_IN_IDENTIFIERS.
* doc/cpp.texi, doc/cppopts.texi, doc/invoke.texi, doc/tm.texi:
Update documentation.
testsuite:
* gcc.dg/dollar.c: New test.
From-SVN: r66911
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 15 | ||||
-rw-r--r-- | gcc/c-common.c | 7 | ||||
-rw-r--r-- | gcc/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-opts.c | 7 | ||||
-rw-r--r-- | gcc/config/alpha/vms.h | 3 | ||||
-rw-r--r-- | gcc/config/darwin.h | 3 | ||||
-rw-r--r-- | gcc/config/m68hc11/m68hc11.h | 3 | ||||
-rw-r--r-- | gcc/cpphash.h | 6 | ||||
-rw-r--r-- | gcc/cppinit.c | 29 | ||||
-rw-r--r-- | gcc/cpplex.c | 6 | ||||
-rw-r--r-- | gcc/doc/cpp.texi | 18 | ||||
-rw-r--r-- | gcc/doc/cppopts.texi | 8 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 10 | ||||
-rw-r--r-- | gcc/doc/tm.texi | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/dollar.c | 9 |
16 files changed, 87 insertions, 53 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 85bea25..0bdb1d4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2003-05-17 Neil Booth <neil@daikokuya.co.uk> + + * c-common.c, c-common.h (dollars_in_ident): Remove. + * c-opts.c (DOLLARS_IN_IDENTIFIERS): Default to true. + (c_common_init_options, c_common_decode_option): Set dollars_in_ident. + * cpphash.h (warned_dollar): Rename warn_dollars. + * cppinit.c (struct lang_flags, lang_defaults, cpp_set_lang) + Permit dollars regardless of -std=. + (post_options): Set warn_dollars. + * cpplex.c (forms_identifier_p): Use warn_dollars. + * config/darwin.h, config/alpha/vms.h, config/m68hc11/m68hc11.h: + Remove redundant definitions of DOLLARS_IN_IDENTIFIERS. + * doc/cpp.texi, doc/cppopts.texi, doc/invoke.texi, doc/tm.texi: + Update documentation. + 2003-05-17 Andreas Schwab <schwab@suse.de> * config/m68k/m68k.c (m68k_output_function_prologue): Use diff --git a/gcc/c-common.c b/gcc/c-common.c index c3fcf42..2bef8dc 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -264,13 +264,6 @@ int flag_no_asm; int flag_const_strings; -/* Nonzero means `$' can be in an identifier. */ - -#ifndef DOLLARS_IN_IDENTIFIERS -#define DOLLARS_IN_IDENTIFIERS 1 -#endif -int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; - /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */ int flag_signed_bitfields = 1; diff --git a/gcc/c-common.h b/gcc/c-common.h index bdea555..f43f6d6 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -434,10 +434,6 @@ extern int flag_no_asm; extern int flag_const_strings; -/* Nonzero means `$' can be in an identifier. */ - -extern int dollars_in_ident; - /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */ extern int flag_signed_bitfields; diff --git a/gcc/c-opts.c b/gcc/c-opts.c index ea2cef4..e2722b3 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -36,6 +36,10 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "c-incpath.h" #include "debug.h" /* For debug_hooks. */ +#ifndef DOLLARS_IN_IDENTIFIERS +# define DOLLARS_IN_IDENTIFIERS true +#endif + #ifndef TARGET_SYSTEM_ROOT # define TARGET_SYSTEM_ROOT NULL #endif @@ -590,6 +594,7 @@ c_common_init_options (lang) parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX, ident_hash); cpp_opts = cpp_get_options (parse_in); + cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; if (flag_objc) cpp_opts->objc = 1; @@ -1157,7 +1162,7 @@ c_common_decode_option (argc, argv) break; case OPT_fdollars_in_identifiers: - dollars_in_ident = on; + cpp_opts->dollars_in_ident = on; break; case OPT_fdump: diff --git a/gcc/config/alpha/vms.h b/gcc/config/alpha/vms.h index 57d8e697..ab75833 100644 --- a/gcc/config/alpha/vms.h +++ b/gcc/config/alpha/vms.h @@ -41,9 +41,6 @@ Boston, MA 02111-1307, USA. */ builtin_define ("__IEEE_FLOAT"); \ } while (0) -/* By default, allow $ to be part of an identifier. */ -#define DOLLARS_IN_IDENTIFIERS 2 - #undef TARGET_DEFAULT #define TARGET_DEFAULT (MASK_FP|MASK_FPREGS|MASK_GAS) #undef TARGET_ABI_OPEN_VMS diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 1e85788..d3f09da 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -287,9 +287,6 @@ Boston, MA 02111-1307, USA. */ to put anything in ENDFILE_SPEC. */ /* #define ENDFILE_SPEC "" */ -#undef DOLLARS_IN_IDENTIFIERS -#define DOLLARS_IN_IDENTIFIERS 2 - /* We use Dbx symbol format. */ #define DBX_DEBUGGING_INFO 1 diff --git a/gcc/config/m68hc11/m68hc11.h b/gcc/config/m68hc11/m68hc11.h index fc9f02a..d2c7090 100644 --- a/gcc/config/m68hc11/m68hc11.h +++ b/gcc/config/m68hc11/m68hc11.h @@ -1706,9 +1706,6 @@ do { \ purposes) so give the MEM rtx a byte's mode. */ #define FUNCTION_MODE QImode -/* Allow $ in identifiers */ -#define DOLLARS_IN_IDENTIFIERS 1 - extern int debug_m6811; extern int z_replacement_completed; extern int current_function_interrupt; diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 210380e..aa5eec4 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -378,9 +378,9 @@ struct cpp_reader cpp_token avoid_paste; cpp_token eof; - /* True if we have already warned about dollars in identifiers or - numbers for this buffer. */ - bool warned_dollar; + /* 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 cdcac25..d6e7ae4 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -73,22 +73,20 @@ struct lang_flags char cplusplus; char extended_numbers; char std; - char dollars_in_ident; char cplusplus_comments; char digraphs; }; -/* ??? Enable $ in identifiers in assembly? */ static const struct lang_flags lang_defaults[] = -{ /* c99 c++ xnum std dollar c++comm digr */ - /* GNUC89 */ { 0, 0, 1, 0, 1, 1, 1 }, - /* GNUC99 */ { 1, 0, 1, 0, 1, 1, 1 }, - /* STDC89 */ { 0, 0, 0, 1, 0, 0, 0 }, - /* STDC94 */ { 0, 0, 0, 1, 0, 0, 1 }, - /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1 }, - /* GNUCXX */ { 0, 1, 1, 0, 1, 1, 1 }, - /* CXX98 */ { 0, 1, 1, 1, 0, 1, 1 }, - /* ASM */ { 0, 0, 1, 0, 0, 1, 0 } +{ /* c99 c++ xnum std // digr */ + /* GNUC89 */ { 0, 0, 1, 0, 1, 1 }, + /* GNUC99 */ { 1, 0, 1, 0, 1, 1 }, + /* STDC89 */ { 0, 0, 0, 1, 0, 0 }, + /* STDC94 */ { 0, 0, 0, 1, 0, 1 }, + /* STDC99 */ { 1, 0, 1, 1, 1, 1 }, + /* GNUCXX */ { 0, 1, 1, 0, 1, 1 }, + /* CXX98 */ { 0, 1, 1, 1, 1, 1 }, + /* ASM */ { 0, 0, 1, 0, 1, 0 } }; /* Sets internal flags correctly for a given language. */ @@ -106,7 +104,6 @@ cpp_set_lang (pfile, lang) CPP_OPTION (pfile, extended_numbers) = l->extended_numbers; CPP_OPTION (pfile, std) = l->std; CPP_OPTION (pfile, trigraphs) = l->std; - CPP_OPTION (pfile, dollars_in_ident) = l->dollars_in_ident; CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments; CPP_OPTION (pfile, digraphs) = l->digraphs; } @@ -153,6 +150,7 @@ cpp_create_reader (lang, table) CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, warn_deprecated) = 1; CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); + CPP_OPTION (pfile, dollars_in_ident) = 1; /* Default CPP arithmetic to something sensible for the host for the benefit of dumb users like fix-header. */ @@ -572,4 +570,11 @@ 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 5f3e3f6..a79bedd 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -402,11 +402,9 @@ forms_identifier_p (pfile, first) return false; buffer->cur++; - if (CPP_PEDANTIC (pfile) - && !pfile->state.skipping - && !pfile->warned_dollar) + if (pfile->warn_dollars && !pfile->state.skipping) { - pfile->warned_dollar = true; + pfile->warn_dollars = false; cpp_error (pfile, DL_PEDWARN, "'$' in identifier or number"); } diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index 62da31f..d1ade81 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -3706,6 +3706,24 @@ execution character set. Currently, GNU cpp only supports character sets that are strict supersets of ASCII, and performs no translation of characters. +@item Identifier characters. +@anchor{Identifier characters} + +The C and C++ standards allow identifiers to be composed of @samp{_} +and the alphanumeric characters. C++ and C99 also allow universal +character names (not implemented in GCC), and C99 further permits +implementation-defined characters. + +GCC allows the @samp{$} character in identifiers as an extension for +most targets. This is true regardless of the @option{std=} switch, +since this extension cannot conflict with standards-conforming +programs. Currently the targets that by default do not permit +@samp{$} are AVR, IP2K, MMIX, MIPS Irix 3, ARM aout, and PowerPC +targets for the AIX and BeOS operating systems. + +You can override the default with @option{-fdollars-in-identifiers} or +@option{fno-dollars-in-identifiers}. @xref{fdollars-in-identifiers}. + @item Non-empty sequences of whitespace characters. In textual output, each whitespace sequence is collapsed to a single diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index 27530c7..7011639 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -468,6 +468,14 @@ is applied to the standard system directories. @xref{System Headers}. @end ifset +@item -fdollars-in-identifiers +@opindex fdollars-in-identifiers +@anchor{fdollars-in-identifiers} +Accept @samp{$} in identifiers. +@ifset cppmanual + @xref{Identifier characters}. +@end ifset + @item -fpreprocessed @opindex fpreprocessed Indicate to the preprocessor that the input file has already been diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 778454d..2ad66e0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -172,7 +172,7 @@ in the following sections. @item C++ Language Options @xref{C++ Dialect Options,,Options Controlling C++ Dialect}. @gccoptlist{-fabi-version=@var{n} -fno-access-control -fcheck-new @gol --fconserve-space -fno-const-strings -fdollars-in-identifiers @gol +-fconserve-space -fno-const-strings @gol -fno-elide-constructors @gol -fno-enforce-eh-specs -fexternal-templates @gol -falt-external-templates @gol @@ -1313,14 +1313,6 @@ This option might be removed in a future release of G++. For maximum portability, you should structure your code so that it works with string constants that have type @code{const char *}. -@item -fdollars-in-identifiers -@opindex fdollars-in-identifiers -Accept @samp{$} in identifiers. You can also explicitly prohibit use of -@samp{$} with the option @option{-fno-dollars-in-identifiers}. (GNU C allows -@samp{$} by default on most target systems, but there are a few exceptions.) -Traditional C allowed the character @samp{$} to form part of -identifiers. However, ISO C and C++ forbid @samp{$} in identifiers. - @item -fno-elide-constructors @opindex fno-elide-constructors The C++ standard allows an implementation to omit creating a temporary diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index d631bd8..01b4975 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -9064,10 +9064,10 @@ value. @findex DOLLARS_IN_IDENTIFIERS @item DOLLARS_IN_IDENTIFIERS -Define this macro to control use of the character @samp{$} in identifier -names. 0 means @samp{$} is not allowed by default; 1 means it is allowed. -1 is the default; there is no need to define this macro in that case. -This macro controls the compiler proper; it does not affect the preprocessor. +Define this macro to control use of the character @samp{$} in +identifier names for the C family of languages. 0 means @samp{$} is +not allowed by default; 1 means it is allowed. 1 is the default; +there is no need to define this macro in that case. @findex NO_DOLLAR_IN_LABEL @item NO_DOLLAR_IN_LABEL diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index edca0dd..abbf2ed 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-05-17 Neil Booth <neil@daikokuya.co.uk> + + * gcc.dg/dollar.c: New test. + 2003-05-16 Janis Johnson <janis187@us.ibm.com> * gcc.dg/compat/struct-by-value-4_main.c: Split into multiple tests. diff --git a/gcc/testsuite/gcc.dg/dollar.c b/gcc/testsuite/gcc.dg/dollar.c new file mode 100644 index 0000000..43407f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/dollar.c @@ -0,0 +1,9 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. */ + +/* { dg-do compile } */ +/* { dg-options -fno-dollars-in-identifiers } */ + +/* Test that -fno-dollars-in-identifiers is honoured. + Neil Booth, 17 May 2003. */ + +int foobar$; /* { dg-error "stray '\\$'" } */ |