From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1377 invoked by alias); 29 Nov 2003 15:48:01 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 1360 invoked from network); 29 Nov 2003 15:47:58 -0000 Received: from unknown (HELO mallaury.noc.nerim.net) (62.4.17.106) by sources.redhat.com with SMTP; 29 Nov 2003 15:47:58 -0000 Received: from tetto.gentiane.org (espie.gentiane.org [62.212.102.210]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 3D9A762D61; Sat, 29 Nov 2003 16:47:55 +0100 (CET) Received: from tetto.gentiane.org (espie@localhost [127.0.0.1]) by tetto.gentiane.org (8.12.9/8.12.1) with ESMTP id hATFlr8m027343; Sat, 29 Nov 2003 16:47:55 +0100 (CET) Received: (from espie@localhost) by tetto.gentiane.org (8.12.9/8.12.1/Submit) id hATFlkio007843; Sat, 29 Nov 2003 16:47:47 +0100 (CET) Date: Sat, 29 Nov 2003 18:14:00 -0000 From: Marc Espie To: Andreas Schwab Cc: gcc@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: PATCH: work-around for bug in -traditional-cpp Message-ID: <20031129154742.GA17134@tetto.gentiane.org> Reply-To: espie@nerim.net References: <20031125125336.GA3717@tetto.gentiane.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-SW-Source: 2003-11/txt/msg01511.txt.bz2 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 * 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. */