This is the mail archive of the gcc-bugs@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: Serious error-causing change in new CPP's -traditional behavior


On Fri, May 05, 2000 at 12:34:56PM -0700, Zack Weinberg wrote:

 > I agree this is a bug.  The macro expander is being overhauled right
 > now, and we don't test -traditional mode much.  Could you try to come
 > up with a test case in C, not assembly?  Then it can be put into the
 > test suite.

I would be happy to.  It is appended at the end of this message.

With old CPP:

dr-evil:thorpej 150$ cc -traditional-cpp cppbug.c                 
dr-evil:thorpej 151$ ./a.out
hello world


With new CPP:

dr-evil:thorpej 152$ /usr/local/bin/gcc -traditional-cpp cppbug.c 
cppbug.c:11: parse error before `Yhello'
cppbug.c: In function `Yhello':
cppbug.c:11: `X' undeclared (first use in this function)
cppbug.c:11: (Each undeclared identifier is reported only once
cppbug.c:11: for each function it appears in.)
cppbug.c:11: parse error before `hello'


While I'm here, I actually have another CPP problem which I haven't
brought to the attention of the list yet.  It has to do with support
for lint(1).  In NetBSD, we added a -CC option to cccp, which is
described as:

       -C     Do not discard comments: pass them through  to  the
              output  file.  Comments appearing in arguments of a
              macro call will be copied to the output before  the
              expansion of the macro call.

       -CC    In  addition  to not discarding comments, make sure
              that a comment that is part  of  the  body  of  the
              macro  definition, gets expanded in the location of
              the macro expansion. This  is  useful  for  lint(1)
              comments.

This is necessary for thing like:

#define FOO do { statement1; statement2; } while (/*CONSTCOND*/0)

Christos Zoulas made the changes, and I thought he fed them back to
Cygnus/FSF, but if cccp was being replaced with cpplib, I guess it's
possible that they either fell through the cracks, were rejected, or
Christos simply forgot to send them.

I'd be happy to send you those old cccp diffs if you like, and would
greatly appreciate the feature in cpplib :-)

However, even when I tried to use -C with cpplib, it complained an
awful lot.  I took a stab at fixing these problems, but I clearly
wasn't getting it right.  I will send a separate message regarding
-C.

 > This should be fixed within the next couple of weeks.  I can't provide
 > an immediate patch, because the code is in flux.

Okay, that's fine.  I try and track it on a day-to-day basis.

-- 
        -- Jason R. Thorpe <thorpej@zembu.com>

/* Test for proper comment elimination semantics from cpplib's -traditional.
   This should compile and link with compiled with `gcc -traditional-cpp'.  */

#define A(name) X/**/name

#define B(name) \
void A(Y/**/name)() { A(name)(); }

void Xhello() { printf("hello world\n"); }

B(hello)

int main() { XYhello(); return (0); }

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