From: Marc Espie <espie@nerim.net>
To: Andreas Schwab <schwab@suse.de>
Cc: gcc@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: PATCH: work-around for bug in -traditional-cpp
Date: Sat, 29 Nov 2003 17:41:00 -0000 [thread overview]
Message-ID: <20031129154742.GA17134@tetto.gentiane.org> (raw)
In-Reply-To: <jeu14sh92h.fsf@sykes.suse.de>
On Tue, Nov 25, 2003 at 02:27:50PM +0100, Andreas Schwab wrote:
> An even simpler test case:
>
> #define a(b,c)
> #if 0
> #define b(x,y) a(x)
> #endif
>
> cpp.c:3: macro "a" requires 2 arguments, but only 1 given
>
> Interestingly, changing #if 0 to #if 1 removes the error.
Okay, it looks like trad-cpp is messing with skipping.
I have at least a work-around for the bug.
It probably means cpp -traditional will no longer emit some needed
warnings, but it will at least stop emitting bogus ones.
2003-11-29 Marc Espie <espie@openbsd.org>
* cpphash.h (_cpp_arguments_ok): Add extra argument.
* cppmacro.c (_cpp_argument_ok, collect_args): Define and use
extra argument silent to remove diagnostic messages.
* cpptrad.c (scan_out_logical_line): Use silent to remove bogus
diagnostic messages.
Index: cpphash.h
===================================================================
RCS file: /cvs/src/gnu/usr.bin/gcc/gcc/cpphash.h,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 cpphash.h
*** cpphash.h 29 Nov 2003 12:21:46 -0000 1.1.1.1
--- cpphash.h 29 Nov 2003 15:45:22 -0000
*************** extern bool _cpp_save_parameter PARAMS
*** 503,509 ****
cpp_hashnode *));
extern bool _cpp_arguments_ok PARAMS ((cpp_reader *, cpp_macro *,
const cpp_hashnode *,
! unsigned int));
extern const uchar *_cpp_builtin_macro_text PARAMS ((cpp_reader *,
cpp_hashnode *));
int _cpp_warn_if_unused_macro PARAMS ((cpp_reader *, cpp_hashnode *,
--- 503,509 ----
cpp_hashnode *));
extern bool _cpp_arguments_ok PARAMS ((cpp_reader *, cpp_macro *,
const cpp_hashnode *,
! unsigned int, int));
extern const uchar *_cpp_builtin_macro_text PARAMS ((cpp_reader *,
cpp_hashnode *));
int _cpp_warn_if_unused_macro PARAMS ((cpp_reader *, cpp_hashnode *,
Index: cppmacro.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/gcc/gcc/cppmacro.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 cppmacro.c
*** cppmacro.c 29 Nov 2003 12:21:50 -0000 1.1.1.1
--- cppmacro.c 29 Nov 2003 15:45:23 -0000
*************** paste_all_tokens (pfile, lhs)
*** 520,530 ****
Note that MACRO cannot necessarily be deduced from NODE, in case
NODE was redefined whilst collecting arguments. */
bool
! _cpp_arguments_ok (pfile, macro, node, argc)
cpp_reader *pfile;
cpp_macro *macro;
const cpp_hashnode *node;
unsigned int argc;
{
if (argc == macro->paramc)
return true;
--- 520,531 ----
Note that MACRO cannot necessarily be deduced from NODE, in case
NODE was redefined whilst collecting arguments. */
bool
! _cpp_arguments_ok (pfile, macro, node, argc, silent)
cpp_reader *pfile;
cpp_macro *macro;
const cpp_hashnode *node;
unsigned int argc;
+ int silent;
{
if (argc == macro->paramc)
return true;
*************** _cpp_arguments_ok (pfile, macro, node, a
*** 541,560 ****
if (argc + 1 == macro->paramc && macro->variadic)
{
! if (CPP_PEDANTIC (pfile) && ! macro->syshdr)
cpp_error (pfile, DL_PEDWARN,
"ISO C99 requires rest arguments to be used");
return true;
}
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" requires %u arguments, but only %u given",
! NODE_NAME (node), macro->paramc, argc);
}
else
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" passed %u arguments, but takes just %u",
! NODE_NAME (node), argc, macro->paramc);
return false;
}
--- 542,563 ----
if (argc + 1 == macro->paramc && macro->variadic)
{
! if (CPP_PEDANTIC (pfile) && ! macro->syshdr && !silent)
cpp_error (pfile, DL_PEDWARN,
"ISO C99 requires rest arguments to be used");
return true;
}
! if (!silent)
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" requires %u arguments, but only %u given",
! NODE_NAME (node), macro->paramc, argc);
}
else
! if (!silent)
! cpp_error (pfile, DL_ERROR,
! "macro \"%s\" passed %u arguments, but takes just %u",
! NODE_NAME (node), argc, macro->paramc);
return false;
}
*************** collect_args (pfile, node)
*** 674,680 ****
/* A single empty argument is counted as no argument. */
if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
argc = 0;
! if (_cpp_arguments_ok (pfile, macro, node, argc))
{
/* GCC has special semantics for , ## b where b is a varargs
parameter: we remove the comma if b was omitted entirely.
--- 677,683 ----
/* A single empty argument is counted as no argument. */
if (argc == 1 && macro->paramc == 0 && args[0].count == 0)
argc = 0;
! if (_cpp_arguments_ok (pfile, macro, node, argc, false))
{
/* GCC has special semantics for , ## b where b is a varargs
parameter: we remove the comma if b was omitted entirely.
Index: cpptrad.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/gcc/gcc/cpptrad.c,v
retrieving revision 1.1.1.1
diff -c -p -r1.1.1.1 cpptrad.c
*** cpptrad.c 29 Nov 2003 12:21:52 -0000 1.1.1.1
--- cpptrad.c 29 Nov 2003 15:45:23 -0000
*************** scan_out_logical_line (pfile, macro)
*** 665,671 ****
&& out == pfile->out.base + fmacro.offset + 1)
fmacro.argc = 0;
! if (_cpp_arguments_ok (pfile, m, fmacro.node, fmacro.argc))
{
/* Remove the macro's invocation from the
output, and push its replacement text. */
--- 665,671 ----
&& out == pfile->out.base + fmacro.offset + 1)
fmacro.argc = 0;
! if (_cpp_arguments_ok (pfile, m, fmacro.node, fmacro.argc, true))
{
/* Remove the macro's invocation from the
output, and push its replacement text. */
next parent reply other threads:[~2003-11-29 15:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20031125125336.GA3717@tetto.gentiane.org>
[not found] ` <jeu14sh92h.fsf@sykes.suse.de>
2003-11-29 17:41 ` Marc Espie [this message]
2003-11-29 22:46 ` Neil Booth
2003-11-30 0:15 ` Marc Espie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031129154742.GA17134@tetto.gentiane.org \
--to=espie@nerim.net \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc@gcc.gnu.org \
--cc=schwab@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).