diff options
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cpplex.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp-tradwarn2.c | 14 |
3 files changed, 25 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d740525..a0a49c7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/cpplex.c b/gcc/cpplex.c index b75db74..189333b 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -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 index 0000000..783b7bc --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp-tradwarn2.c @@ -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" } */ +} |