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]

Re: Simple CPP failure (snapshot 20000313)


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;
Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]