This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Dollars in identifiers, for the last time


Dollars in identifier handling has been screwed for all of the 3.x
series I believe.  For 3.3 and 3.4, -f[no-]dollars-in-identifiers is
being completely ignored.

This patch sorts it out for good.  We accept dollars iff
DOLLARS_IN_IDENTIFIERS, but this default can be overridden on
the command line.  We warn if pedantic and not C99, since C99 permits
implementation-defined chars in identifiers, and I've documented
our choice.  There is no good reason to reject '$' even for -std=c89
based on our accepted meaning of -std=, so we don't, as documented.

I'm testing on x86-netbsd and will apply it if successful.

Neil.

	* 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.

============================================================
Index: gcc/c-common.c
--- gcc/c-common.c	11 May 2003 12:47:41 -0000	1.415
+++ gcc/c-common.c	17 May 2003 19:58:54 -0000
@@ -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: gcc/c-common.h
--- gcc/c-common.h	20 Apr 2003 22:58:28 -0000	1.178
+++ gcc/c-common.h	17 May 2003 19:58:55 -0000
@@ -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: gcc/c-opts.c
--- gcc/c-opts.c	13 May 2003 18:06:43 -0000	1.46
+++ gcc/c-opts.c	17 May 2003 19:58:55 -0000
@@ -36,6 +36,10 @@ Software Foundation, 59 Temple Place - S
 #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: gcc/cpphash.h
--- gcc/cpphash.h	21 Apr 2003 19:21:57 -0000	1.186
+++ gcc/cpphash.h	17 May 2003 19:58:55 -0000
@@ -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: gcc/cppinit.c
--- gcc/cppinit.c	11 May 2003 15:15:35 -0000	1.280
+++ gcc/cppinit.c	17 May 2003 19:58:56 -0000
@@ -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: gcc/cpplex.c
--- gcc/cpplex.c	4 May 2003 20:03:54 -0000	1.234
+++ gcc/cpplex.c	17 May 2003 19:58:56 -0000
@@ -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: gcc/config/darwin.h
--- gcc/config/darwin.h	12 May 2003 09:51:18 -0000	1.51
+++ gcc/config/darwin.h	17 May 2003 19:58:56 -0000
@@ -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: gcc/config/alpha/vms.h
--- gcc/config/alpha/vms.h	16 Dec 2002 18:20:48 -0000	1.69
+++ gcc/config/alpha/vms.h	17 May 2003 19:58:56 -0000
@@ -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: gcc/config/m68hc11/m68hc11.h
--- gcc/config/m68hc11/m68hc11.h	14 May 2003 07:29:50 -0000	1.73
+++ gcc/config/m68hc11/m68hc11.h	17 May 2003 19:58:57 -0000
@@ -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: gcc/doc/cpp.texi
--- gcc/doc/cpp.texi	11 May 2003 20:16:39 -0000	1.57
+++ gcc/doc/cpp.texi	17 May 2003 19:58:59 -0000
@@ -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.  The C90 and C++ standards do not
+permit anything else, but C99 allows additional implementation-defined
+characters.
+
+GCC additionally 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: gcc/doc/cppopts.texi
--- gcc/doc/cppopts.texi	16 May 2003 23:38:42 -0000	1.23
+++ gcc/doc/cppopts.texi	17 May 2003 19:58:59 -0000
@@ -468,6 +468,14 @@ is applied to the standard system direct
 @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: gcc/doc/invoke.texi
--- gcc/doc/invoke.texi	17 May 2003 18:20:54 -0000	1.277
+++ gcc/doc/invoke.texi	17 May 2003 19:59:03 -0000
@@ -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
@@ -1312,14 +1312,6 @@ actually modify the value of a string co
 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
============================================================
Index: gcc/doc/tm.texi
--- gcc/doc/tm.texi	14 May 2003 07:29:54 -0000	1.218
+++ gcc/doc/tm.texi	17 May 2003 19:59:07 -0000
@@ -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: gcc/testsuite/gcc.dg/dollar.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/dollar.c	17 May 2003 19:59:07 -0000
@@ -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 '$'" } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]