c-common.c, c-common.h (dollars_in_ident): Remove.
authorNeil Booth <neil@daikokuya.co.uk>
Sat, 17 May 2003 20:29:34 +0000 (20:29 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sat, 17 May 2003 20:29:34 +0000 (20:29 +0000)
* 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

16 files changed:
gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-opts.c
gcc/config/alpha/vms.h
gcc/config/darwin.h
gcc/config/m68hc11/m68hc11.h
gcc/cpphash.h
gcc/cppinit.c
gcc/cpplex.c
gcc/doc/cpp.texi
gcc/doc/cppopts.texi
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/dollar.c [new file with mode: 0644]

index 85bea2534930db06ab67093d3a13be208aa9b011..0bdb1d48f359a6687ff64735dac4e4cf2a6ff988 100644 (file)
@@ -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
index c3fcf42e8d10eea8b8e2b16dc924dba90e758bde..2bef8dccf86fb16d20d8e02cd8a8277d5edbe613 100644 (file)
@@ -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;
index bdea5559b73e6569e2be68787d7e0f43362eb88d..f43f6d66d956e4fc1181c809fe4775d76421bddb 100644 (file)
@@ -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;
index ea2cef42899cf6eb32425475216eb25ec2856184..e2722b37f743aeeb5f900d82903b8f09154fec03 100644 (file)
@@ -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:
index 57d8e697c466b1e0be73532b7c356b1f25612471..ab758335c76e33b703d91a2aae509ee755e5ef1a 100644 (file)
@@ -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
index 1e857887aa7dc0c2276286985d472c20c4507623..d3f09da1351c2d0a663cb62118b2012d442adfb4 100644 (file)
@@ -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
index fc9f02a446db3bfa369ba5ba3d6520f250cfd3ba..d2c70906ce6446caf7b827bc2b941258286ca56f 100644 (file)
@@ -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;
index 210380ed0c209ad926e0a644214cbe28ab8b3a65..aa5eec4e9d44018183acfe27d212d0873c9531d2 100644 (file)
@@ -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;
index cdcac255d672f74895e66e6b681b3e759c53607a..d6e7ae426d2ec190c45d32e1d7c01ad8709c366d 100644 (file)
@@ -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);
 }
index 5f3e3f62fcb5ee617482893296cf624e2050a1ad..a79bedd154db28029cf9b0df48b6f33960d0b19f 100644 (file)
@@ -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");
        }
 
index 62da31fdfbb0de75f58b363d06f4ce40222d0601..d1ade8112ea1f875474e046173852c3d2cb0d3ef 100644 (file)
@@ -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
index 27530c751eb68ab99b7d9f701669ceb379487f58..70116399dc784b4b5adbc239ec94f5dbd3b5da21 100644 (file)
@@ -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
index 778454d4b01fa51115163c893d76b0df9f839244..2ad66e0159d4adb258eea16b80498f707718cdbe 100644 (file)
@@ -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
index d631bd8e7af4b8ebd7bf287cdd06317cd3967a85..01b49753dc334c2fea2e5c871c2dc2e7895184aa 100644 (file)
@@ -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
index edca0ddaf416afccfa00e1fd5281cdf1386071e1..abbf2ed0fc8a156d2106a14178133ae537e21852 100644 (file)
@@ -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 (file)
index 0000000..43407f2
--- /dev/null
@@ -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 '\\$'" } */