c-opts.c (warn_variadic_macros): New.
authorRichard Henderson <rth@redhat.com>
Thu, 19 Feb 2004 22:18:50 +0000 (14:18 -0800)
committerRichard Henderson <rth@gcc.gnu.org>
Thu, 19 Feb 2004 22:18:50 +0000 (14:18 -0800)
        * 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
gcc/c-opts.c
gcc/c.opt
gcc/cppinit.c
gcc/cpplib.h
gcc/cppmacro.c

index 2319cf3dc3dbadbb8dc531cc87fb39fbd4ffef2b..6ab7b701cd2041324aaea62ef679eff36f99f902 100644 (file)
@@ -1,3 +1,13 @@
+2004-02-19  Richard Henderson  <rth@redhat.com>
+
+       * 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 <ddaney@avtrex.com>
 
        PR preprocessor/14198
index a0d7382796fa1808bb1afa3ab1567c84fc5b5213..c9b34db492169a61b745c76971de9f2ac18df9a0 100644 (file)
@@ -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
index 2a2ff85b738067276ada5bccf459d8b171e21a17..0674627bb921f1d01a53143211398fed639536cc 100644 (file)
--- 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\"
index ed91b0e6ea19f0311adecf02ec7050990f55ef66..a6da0b69b6f6186727d81ff6682260068a891b5d 100644 (file)
@@ -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.  */
index ffbfe1bf84a593474347dcd3e685593439df512c..dddbac2a4517575df63cb48cef1c8c802862d8ea 100644 (file)
@@ -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;
 
index f4e885740b4255ee59d9ffe2cd72f5f2a048e122..065c3972016656fbebd8a481b145350486e11abc 100644 (file)
@@ -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");