From e5b792193379be3beab505f1a72fb4fedaf62e6b Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 19 Feb 2004 14:18:50 -0800 Subject: [PATCH] c-opts.c (warn_variadic_macros): New. * c-opts.c (warn_variadic_macros): New. (c_common_handle_option): Set it. (sanitize_cpp_opts): Copy it to cpp_opts. * c.opt (Wvariadic-macros): New. * cpplib.h (struct cpp_options): Add warn_variadic_macros. * cppinit.c (cpp_create_reader): Initialize it. * cppmacro.c (parse_params): Check it. From-SVN: r78125 --- gcc/ChangeLog | 10 ++++++++++ gcc/c-opts.c | 12 ++++++++++++ gcc/c.opt | 4 ++++ gcc/cppinit.c | 1 + gcc/cpplib.h | 4 ++++ gcc/cppmacro.c | 7 +++++-- 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2319cf3..6ab7b70 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2004-02-19 Richard Henderson + + * c-opts.c (warn_variadic_macros): New. + (c_common_handle_option): Set it. + (sanitize_cpp_opts): Copy it to cpp_opts. + * c.opt (Wvariadic-macros): New. + * cpplib.h (struct cpp_options): Add warn_variadic_macros. + * cppinit.c (cpp_create_reader): Initialize it. + * cppmacro.c (parse_params): Check it. + 2004-02-19 David Daney PR preprocessor/14198 diff --git a/gcc/c-opts.c b/gcc/c-opts.c index a0d7382..c9b34db 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -88,6 +88,9 @@ static bool quote_chain_split; /* If -Wunused-macros. */ static bool warn_unused_macros; +/* If -Wvariadic-macros. */ +static bool warn_variadic_macros = true; + /* Number of deferred options. */ static size_t deferred_count; @@ -646,6 +649,10 @@ c_common_handle_option (size_t scode, const char *arg, int value) warn_unused_macros = value; break; + case OPT_Wvariadic_macros: + warn_variadic_macros = value; + break; + case OPT_Wwrite_strings: if (!c_dialect_cxx ()) flag_const_strings = value; @@ -1360,6 +1367,11 @@ sanitize_cpp_opts (void) cpp_opts->warn_long_long = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional); + /* Similarly with -Wno-variadic-macros. No check for c99 here, since + this also turns off warnings about GCCs extension. */ + cpp_opts->warn_variadic_macros + = warn_variadic_macros && (pedantic || warn_traditional); + /* If we're generating preprocessor output, emit current directory if explicitly requested or if debugging information is enabled. ??? Maybe we should only do it for debugging formats that diff --git a/gcc/c.opt b/gcc/c.opt index 2a2ff85..0674627 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -399,6 +399,10 @@ Wunused-macros C ObjC C++ ObjC++ Warn about macros defined in the main file that are not used +Wvariadic-macros +C ObjC C++ ObjC++ +Do not warn about using variadic macros when -pedantic + Wwrite-strings C ObjC C++ ObjC++ Give strings the type \"array of char\" diff --git a/gcc/cppinit.c b/gcc/cppinit.c index ed91b0e..a6da0b6 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -147,6 +147,7 @@ cpp_create_reader (enum c_lang lang, hash_table *table, CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); CPP_OPTION (pfile, dollars_in_ident) = 1; CPP_OPTION (pfile, warn_dollars) = 1; + CPP_OPTION (pfile, warn_variadic_macros) = 1; /* Default CPP arithmetic to something sensible for the host for the benefit of dumb users like fix-header. */ diff --git a/gcc/cpplib.h b/gcc/cpplib.h index ffbfe1b..dddbac2 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -283,6 +283,10 @@ struct cpp_options promotions. */ unsigned char warn_num_sign_change; + /* Zero means don't warn about __VA_ARGS__ usage in c89 pedantic mode. + Presumably the usage is protected by the appropriate #ifdef. */ + unsigned char warn_variadic_macros; + /* Nonzero means turn warnings into errors. */ unsigned char warnings_are_errors; diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index f4e8857..065c397 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -1327,11 +1327,14 @@ parse_params (cpp_reader *pfile, cpp_macro *macro) _cpp_save_parameter (pfile, macro, pfile->spec_nodes.n__VA_ARGS__); pfile->state.va_args_ok = 1; - if (! CPP_OPTION (pfile, c99) && CPP_OPTION (pfile, pedantic)) + if (! CPP_OPTION (pfile, c99) + && CPP_OPTION (pfile, pedantic) + && CPP_OPTION (pfile, warn_variadic_macros)) cpp_error (pfile, CPP_DL_PEDWARN, "anonymous variadic macros were introduced in C99"); } - else if (CPP_OPTION (pfile, pedantic)) + else if (CPP_OPTION (pfile, pedantic) + && CPP_OPTION (pfile, warn_variadic_macros)) cpp_error (pfile, CPP_DL_PEDWARN, "ISO C does not permit named variadic macros"); -- 2.7.4