From 476f28692a80a42632b33b7fb1f0725f81bdbce0 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Fri, 26 May 2000 01:29:35 +0000 Subject: [PATCH] cpplex.c (maybe_macroexpand): Warn about function-like macros used in non-function context, if -Wtraditional. * cpplex.c (maybe_macroexpand): Warn about function-like macros used in non-function context, if -Wtraditional. From-SVN: r34183 --- gcc/ChangeLog | 5 +++++ gcc/cpplex.c | 6 ++++++ gcc/testsuite/gcc.dg/cpp-tradwarn2.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/cpp-tradwarn2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d74052515eb3..a0a49c71768d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2000-05-25 Zack Weinberg + + * cpplex.c (maybe_macroexpand): Warn about function-like + macros used in non-function context, if -Wtraditional. + 2000-05-25 Mark Mitchell * recog.c (peephole2_optimize): Use INSN_P. diff --git a/gcc/cpplex.c b/gcc/cpplex.c index b75db74d4738..189333b4ec22 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 000000000000..783b7bce04d7 --- /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" } */ +} -- 2.47.2