This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Simple CPP failure (snapshot 20000313)
- To: Jonathan Larmour <jlarmour at redhat dot co dot uk>
- Subject: Re: Simple CPP failure (snapshot 20000313)
- From: Neil Booth <NeilB at earthling dot net>
- Date: Thu, 23 Mar 2000 23:42:32 +0900
- Cc: gcc-bugs at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, Zack Weinberg <zack at wolery dot cumb dot org>
- References: <38D92BD3.49E89283@redhat.co.uk>
Jonathan Larmour wrote:-
> CPP does not deal with the following file correctly:
>
> -=-=-=-=-=-=-=- cut here -=-=-=-=-=-=-=-
> #define X (16*(40) + 192)
> #define Y 2048
>
> #if Y < X
> #undef Y
> #define Y X
> #endif
>
> Y
> -=-=-=-=-=-=-=- cut here -=-=-=-=-=-=-=-
Thanks for your bug report. This is being caused by the parser in
cppexp.c deciding that the '+' is unary. It decides this because its
test for a unary +/- is (effectively) "if the previous token is an
operator it's unary, otherwise it's binary".
The problem with this is that ')' is treated as an operator, however
it is not really an operator in it's own right, but more just a
syntactic indicator of the range of the previous '('.
The following patch fixes the problem, and bootstraps. Whether it is
the "correct" patch I'm not so sure.
OK to commit it?
Neil.
Incidentally, one minor problem with the current parser is it allows
too many unary operators, e.g. the following line parses without
warning or error:
#if 1 + + + 1
--
* cppexp.c (_cpp_parse_expr) Correct test for unary +/-.
Index: cppexp.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppexp.c,v
retrieving revision 1.39
diff -u -p -r1.39 cppexp.c
--- cppexp.c 2000/03/13 22:01:06 1.39
+++ cppexp.c 2000/03/23 14:24:01
@@ -717,7 +717,7 @@ _cpp_parse_expr (pfile)
case 0:
lprio = 0; goto maybe_reduce;
case '+': case '-':
- if (top->flags & HAVE_VALUE)
+ if ((top->flags & HAVE_VALUE) || top->op == ')')
{
lprio = PLUS_PRIO;
goto binop;