OSDN Git Service

* cpplex.c (maybe_macroexpand): Warn about function-like
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 26 May 2000 01:29:35 +0000 (01:29 +0000)
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 26 May 2000 01:29:35 +0000 (01:29 +0000)
macros used in non-function context, if -Wtraditional.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@34183 138bc75d-0d04-0410-961f-82ee72b054a4

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

index d740525..a0a49c7 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 b75db74..189333b 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" } */
+}