cpplib: Fix C++ named operators bug
Neil Booth
neil@daikokuya.demon.co.uk
Thu May 23 12:05:00 GMT 2002
We treated them like built-in macros and didn't honour them
if -fpreprocessed. LOL. I just realized this. Shows how much
people really use them, I guess.
This isn't a regression, 3.0 and 3.1 have the bug so I'll just
put this in 3.2.
Neil.
* cppinit.c (mark_named_operators): Split out from init_builtins.
(cpp_finish_options): Call it from here instead.
testsuite:
* gcc.dg/cpp/named_ops.c: New test.
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.232
diff -u -p -r1.232 cppinit.c
--- cppinit.c 23 May 2002 06:07:44 -0000 1.232
+++ cppinit.c 23 May 2002 18:50:50 -0000
@@ -98,6 +98,7 @@ static void path_include PARAMS ((cpp_r
char *, int));
static void init_library PARAMS ((void));
static void init_builtins PARAMS ((cpp_reader *));
+static void mark_named_operators PARAMS ((cpp_reader *));
static void append_include_chain PARAMS ((cpp_reader *,
char *, int, int));
static struct search_path * remove_dup_dir PARAMS ((cpp_reader *,
@@ -664,6 +665,23 @@ static const struct builtin operator_arr
};
#undef B
+/* Mark the C++ named operators in the hash table. */
+static void
+mark_named_operators (pfile)
+ cpp_reader *pfile;
+{
+ const struct builtin *b;
+
+ for (b = operator_array;
+ b < (operator_array + ARRAY_SIZE (operator_array));
+ b++)
+ {
+ cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
+ hp->flags |= NODE_OPERATOR;
+ hp->value.operator = b->value;
+ }
+}
+
/* Subroutine of cpp_read_main_file; reads the builtins table above and
enters them, and language-specific macros, into the hash table. */
static void
@@ -682,16 +700,6 @@ init_builtins (pfile)
hp->value.builtin = b->value;
}
- if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
- for (b = operator_array;
- b < (operator_array + ARRAY_SIZE (operator_array));
- b++)
- {
- cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
- hp->flags |= NODE_OPERATOR;
- hp->value.operator = b->value;
- }
-
if (CPP_OPTION (pfile, cplusplus))
_cpp_define_builtin (pfile, "__cplusplus 1");
else if (CPP_OPTION (pfile, objc))
@@ -976,6 +984,10 @@ void
cpp_finish_options (pfile)
cpp_reader *pfile;
{
+ /* Mark named operators before handling command line macros. */
+ if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
+ mark_named_operators (pfile);
+
/* Install builtins and process command line macros etc. in the order
they appeared, but only if not already preprocessed. */
if (! CPP_OPTION (pfile, preprocessed))
Index: testsuite/gcc.dg/cpp/named_ops.c
===================================================================
RCS file: testsuite/gcc.dg/cpp/named_ops.c
diff -N testsuite/gcc.dg/cpp/named_ops.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/cpp/named_ops.c 23 May 2002 18:50:50 -0000
@@ -0,0 +1,11 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options -fpreprocessed } */
+
+/* Tests that C++ named ops are still there with -fpreprocessed. */
+
+/* Source: Neil Booth, 23 May 2002. */
+
+#if 2 xor 2
+#endif
More information about the Gcc-patches
mailing list