]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cpplex.c (maybe_macroexpand): Warn about function-like macros used in non-function...
authorZack Weinberg <zack@wolery.cumb.org>
Fri, 26 May 2000 01:29:35 +0000 (01:29 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Fri, 26 May 2000 01:29:35 +0000 (01:29 +0000)
* cpplex.c (maybe_macroexpand): Warn about function-like
macros used in non-function context, if -Wtraditional.

From-SVN: r34183

gcc/ChangeLog
gcc/cpplex.c
gcc/testsuite/gcc.dg/cpp-tradwarn2.c [new file with mode: 0644]

index d74052515eb3e5d9d8e28fb6ad783ad39f4fbe80..a0a49c71768d6ee6175686c4c7cf2fef199353bd 100644 (file)
@@ -1,3 +1,8 @@
+2000-05-25  Zack Weinberg  <zack@wolery.cumb.org>
+
+       * cpplex.c (maybe_macroexpand): Warn about function-like
+       macros used in non-function context, if -Wtraditional.
+
 2000-05-25  Mark Mitchell  <mark@codesourcery.com>
 
        * recog.c (peephole2_optimize): Use INSN_P.
index b75db74d473831219d15afab2c3f6fec407e6b44..189333b4ec22c72e4862982b7f84111b7996ca2c 100644 (file)
@@ -1687,6 +1687,12 @@ maybe_macroexpand (pfile, written)
        not_macro_call:
          if (macbuf_whitespace)
            CPP_PUTC (pfile, ' ');
+
+         /* K+R treated this as a hard error.  */
+         if (CPP_OPTION (pfile, warn_traditional))
+           cpp_warning (pfile,
+        "traditional C rejects function macro %s in non-function context",
+                        hp->name);
          return 0;
        }
     }
diff --git a/gcc/testsuite/gcc.dg/cpp-tradwarn2.c b/gcc/testsuite/gcc.dg/cpp-tradwarn2.c
new file mode 100644 (file)
index 0000000..783b7bc
--- /dev/null
@@ -0,0 +1,14 @@
+/* K+R rejects use of function-like macros in non-function context.
+   ANSI C explicitly permits this (the macro is not expanded).  */
+
+/* { dg-do compile } */
+/* { dg-options -Wtraditional } */
+
+enum { SIGN_EXTEND = 23 };
+
+#define SIGN_EXTEND(v) (((v) < 0) ? -1 : 0)
+
+int fun(void)
+{
+  return SIGN_EXTEND;  /* { dg-warning "in non-function context" } */
+}