This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
cpplib: Fix funlike macros and -Wtraditional
- From: Neil Booth <neil at daikokuya dot co dot uk>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: John David Anglin <dave at hiauly1 dot hia dot nrc dot ca>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 20 Sep 2002 19:23:47 +0100
- Subject: cpplib: Fix funlike macros and -Wtraditional
>From my testing, this patch has the desired behaviour in all cases, as
far as I can see.
I'll commit it after bootstrap. Testcase updated.
Neil.
* cppmacro.c: Don't warn about function-like macros without
'(' during pre-expandion.
testsuite:
* gcc.dg/cpp/tr-warn2.c: Update.
Index: gcc/cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.122
diff -u -p -r1.122 cppmacro.c
--- gcc/cppmacro.c 7 Aug 2002 21:47:47 -0000 1.122
+++ gcc/cppmacro.c 20 Sep 2002 18:20:55 -0000
@@ -1032,10 +1032,15 @@ expand_arg (pfile, arg)
macro_arg *arg;
{
unsigned int capacity;
+ bool saved_warn_trad;
if (arg->count == 0)
return;
+ /* Don't warn about funlike macros when pre-expanding. */
+ saved_warn_trad = CPP_WTRADITIONAL (pfile);
+ CPP_WTRADITIONAL (pfile) = 0;
+
/* Loop, reading in the arguments. */
capacity = 256;
arg->expanded = (const cpp_token **)
@@ -1062,6 +1067,8 @@ expand_arg (pfile, arg)
}
_cpp_pop_context (pfile);
+
+ CPP_WTRADITIONAL (pfile) = saved_warn_trad;
}
/* Pop the current context off the stack, re-enabling the macro if the
Index: gcc/testsuite/gcc.dg/cpp/tr-warn2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/cpp/tr-warn2.c,v
retrieving revision 1.2
diff -u -p -r1.2 tr-warn2.c
--- gcc/testsuite/gcc.dg/cpp/tr-warn2.c 3 Jul 2002 02:41:33 -0000 1.2
+++ gcc/testsuite/gcc.dg/cpp/tr-warn2.c 20 Sep 2002 18:20:55 -0000
@@ -1,14 +1,16 @@
/* K+R rejects use of function-like macros in non-function context.
- ANSI C explicitly permits this (the macro is not expanded). */
+ ANSI C explicitly permits this (the macro is not expanded).
-/* { dg-do compile } */
-/* { dg-options -Wtraditional } */
-
-enum { SIGN_EXTEND = 23 };
+ We should not warn about this during pre-expansion of arguments,
+ since traditional preprocessors don't do pre-expansion, and we get
+ the warning anyway during the re-scan pass if and only if it is
+ appropriate. */
-#define SIGN_EXTEND(v) (((v) < 0) ? -1 : 0)
+/* { dg-do preprocess } */
+/* { dg-options -Wtraditional } */
-int fun()
-{
- return SIGN_EXTEND; /* { dg-warning "must be used with arguments" } */
-}
+#define f(x) x
+#define g(x) x / 2
+f(g) (3) /* { dg-bogus "must be used with arguments" } */
+f 2 /* { dg-warning "must be used with arguments" } */
+f(g) 3 /* { dg-warning "must be used with arguments" } */