OSDN Git Service

* diagnostic.h (diagnostic_override_option_index): New macro to
authorsimonb <simonb@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 7 Apr 2010 17:18:10 +0000 (17:18 +0000)
committerMasaki Muranaka <monaka@monami-software.com>
Sun, 23 May 2010 00:50:52 +0000 (09:50 +0900)
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.

* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.

* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
        warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
        warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.

* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.

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

30 files changed:
gcc/ChangeLog
gcc/doc/invoke.texi
gcc/fortran/ChangeLog
gcc/opts.c
gcc/opts.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp/warning-directive-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp/warning-directive-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp/warning-directive-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp/warning-directive-4.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/warn-comments-2.c
gcc/testsuite/gcc.dg/cpp/warn-cxx-compat-2.c
gcc/testsuite/gcc.dg/cpp/warn-deprecated-2.c
gcc/testsuite/gcc.dg/cpp/warn-long-long-2.c
gcc/testsuite/gcc.dg/cpp/warn-multichar-2.c
gcc/testsuite/gcc.dg/cpp/warn-normalized-3.c
gcc/testsuite/gcc.dg/cpp/warn-redefined-2.c
gcc/testsuite/gcc.dg/cpp/warn-traditional-2.c
gcc/testsuite/gcc.dg/cpp/warn-trigraphs-3.c
gcc/testsuite/gcc.dg/cpp/warn-trigraphs-4.c
gcc/testsuite/gcc.dg/cpp/warn-undef-2.c
gcc/testsuite/gcc.dg/cpp/warn-unused-macros-2.c
gcc/testsuite/gcc.dg/cpp/warn-variadic-2.c
gcc/testsuite/gcc.dg/cpp/warning-directive-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/warning-directive-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/warning-directive-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/warning-directive-4.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/warning-directive-2.F90
libcpp/ChangeLog
libcpp/lex.c

index 693d69d..2a6c593 100644 (file)
@@ -1,3 +1,25 @@
+2010-04-07  Simon Baldwin  <simonb@google.com>
+
+       * diagnostic.h (diagnostic_override_option_index): New macro to
+       set a diagnostic's option_index.
+       * c-tree.h (c_cpp_error): Add warning reason argument.
+       * opts.c (_warning_as_error_callback): New.
+       (register_warning_as_error_callback): Store callback for
+       warnings enabled via enable_warning_as_error.
+       (enable_warning_as_error): Call callback, minor code tidy.
+       * opts.h (register_warning_as_error_callback): Declare.
+       * c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
+       response to -Werror=.
+       (c_common_init_options): Register warning_as_error_callback in opts.c.
+       * common.opt: Add -Wno-cpp option.
+       * c-common.c (struct reason_option_codes_t): Map cpp warning
+       reason codes to gcc option indexes.
+       * (c_option_controlling_cpp_error): New function, lookup the gcc
+       option index for a cpp warning reason code.
+       * (c_cpp_error): Add warning reason argument, call
+       c_option_controlling_cpp_error for diagnostic_override_option_index.
+       * doc/invoke.texi: Document -Wno-cpp.
+
 2010-04-07  Richard Guenther  <rguenther@suse.de>
 
        * ipa-reference.c (mark_load): Use get_base_address.
index 76c4240..d356daa 100644 (file)
@@ -232,7 +232,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-attributes -Wno-builtin-macro-redefined @gol
 -Wc++-compat -Wc++0x-compat -Wcast-align  -Wcast-qual  @gol
 -Wchar-subscripts -Wclobbered  -Wcomment @gol
--Wconversion  -Wcoverage-mismatch  -Wno-deprecated  @gol
+-Wconversion  -Wcoverage-mismatch  -Wcpp  -Wno-deprecated  @gol
 -Wno-deprecated-declarations -Wdisabled-optimization  @gol
 -Wno-div-by-zero -Wempty-body  -Wenum-compare -Wno-endif-labels @gol
 -Werror  -Werror=* @gol
@@ -2973,6 +2973,11 @@ Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}
 comment, or whenever a Backslash-Newline appears in a @samp{//} comment.
 This warning is enabled by @option{-Wall}.
 
+@item -Wno-cpp \
+@r{(C, Objective-C, C++, Objective-C++ and Fortran only)}
+
+Suppress warning messages emitted by @code{#warning} directives.
+
 @item -Wformat
 @opindex Wformat
 @opindex Wno-format
index 2b1aa30..6502b89 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-07  Simon Baldwin  <simonb@google.com>
+
+       * cpp.c (cb_cpp_error): Add warning reason argument, set a value
+       for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
+
 2010-04-07  Richard Guenther  <rguenther@suse.de>
 
        * options.c (gfc_init_options): Do not set.
index 329f732..19d5634 100644 (file)
@@ -372,11 +372,13 @@ const char **in_fnames;
 unsigned num_in_fnames;
 
 static int common_handle_option (size_t scode, const char *arg, int value,
-                                unsigned int lang_mask, int kind);
+                                unsigned int lang_mask);
 static void handle_param (const char *);
+static unsigned int handle_option (const char **argv, unsigned int lang_mask);
 static char *write_langs (unsigned int lang_mask);
 static void complain_wrong_lang (const char *, const struct cl_option *,
                                 unsigned int lang_mask);
+static void handle_options (unsigned int, const char **, unsigned int);
 static void set_debug_level (enum debug_info_type type, int extended,
                             const char *arg);
 
@@ -483,57 +485,10 @@ void print_ignored_options (void)
   input_location = saved_loc;
 }
 
-
-/* Handle option OPT_INDEX, and argument ARG, for the language
-   indicated by LANG_MASK.  VALUE is true, unless no- form of an -f or
-   -W option was given.  KIND is the diagnostic_t if this is a
-   diagnostics option, DK_UNSPECIFIED otherwise.  Returns false if the
-   switch was invalid.  */
-bool
-handle_option (int opt_index, int value, const char *arg,
-               unsigned int lang_mask, int kind)
-{
-  const struct cl_option *option = &cl_options[opt_index];
-
-  if (option->flag_var)
-    set_option (opt_index, value, arg, kind);
-  
-  if (option->flags & lang_mask)
-    {
-      if (lang_hooks.handle_option (opt_index, arg, value, kind) == 0)
-       return false;
-#ifdef ENABLE_LTO
-      else
-       lto_register_user_option (opt_index, arg, value, lang_mask);
- #endif
-    }
-
-  if (option->flags & CL_COMMON)
-    {
-      if (common_handle_option (opt_index, arg, value, lang_mask, kind) == 0)
-       return false;
-#ifdef ENABLE_LTO
-      else
-       lto_register_user_option (opt_index, arg, value, CL_COMMON);
-#endif
-    }
-
-  if (option->flags & CL_TARGET)
-    {
-      if (!targetm.handle_option (opt_index, arg, value))
-       return false;
-#ifdef ENABLE_LTO
-      else
-       lto_register_user_option (opt_index, arg, value, CL_TARGET);
-#endif
-    }
-  return true;
-}
-
 /* Handle the switch beginning at ARGV for the language indicated by
    LANG_MASK.  Returns the number of switches consumed.  */
 static unsigned int
-read_cmdline_option (const char **argv, unsigned int lang_mask)
+handle_option (const char **argv, unsigned int lang_mask)
 {
   size_t opt_index;
   const char *opt, *arg = 0;
@@ -654,8 +609,32 @@ read_cmdline_option (const char **argv, unsigned int lang_mask)
        }
     }
 
-  if (!handle_option (opt_index, value, arg, lang_mask, DK_UNSPECIFIED))
-    result = 0;
+  if (option->flag_var)
+    set_option (option, value, arg);
+
+  if (option->flags & lang_mask)
+    {
+      if (lang_hooks.handle_option (opt_index, arg, value) == 0)
+       result = 0;
+      else
+       lto_register_user_option (opt_index, arg, value, lang_mask);
+    }
+
+  if (result && (option->flags & CL_COMMON))
+    {
+      if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
+       result = 0;
+      else
+       lto_register_user_option (opt_index, arg, value, CL_COMMON);
+    }
+
+  if (result && (option->flags & CL_TARGET))
+    {
+      if (!targetm.handle_option (opt_index, arg, value))
+       result = 0;
+      else
+       lto_register_user_option (opt_index, arg, value, CL_TARGET);
+    }
 
  done:
   if (dup)
@@ -756,7 +735,7 @@ flag_instrument_functions_exclude_p (tree fndecl)
    contains has a single bit set representing the current
    language.  */
 static void
-read_cmdline_options (unsigned int argc, const char **argv, unsigned int lang_mask)
+handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
 {
   unsigned int n, i;
 
@@ -778,7 +757,7 @@ read_cmdline_options (unsigned int argc, const char **argv, unsigned int lang_ma
          continue;
        }
 
-      n = read_cmdline_option (argv + i, lang_mask);
+      n = handle_option (argv + i, lang_mask);
 
       if (!n)
        {
@@ -879,7 +858,6 @@ decode_options (unsigned int argc, const char **argv)
   flag_if_conversion2 = opt1;
   flag_ipa_pure_const = opt1;
   flag_ipa_reference = opt1;
-  flag_ipa_profile = opt1;
   flag_merge_constants = opt1;
   flag_split_wide_types = opt1;
   flag_tree_ccp = opt1;
@@ -967,9 +945,6 @@ decode_options (unsigned int argc, const char **argv)
   else
     set_param_value ("min-crossjump-insns", initial_min_crossjump_insns);
 
-  /* Enable -Werror=coverage-mismatch by default */
-  enable_warning_as_error("coverage-mismatch", 1, lang_mask);
-
   if (first_time_p)
     {
       /* Initialize whether `char' is signed.  */
@@ -986,17 +961,15 @@ decode_options (unsigned int argc, const char **argv)
       flag_unwind_tables = targetm.unwind_tables_default;
     }
 
-#ifdef ENABLE_LTO
   /* Clear any options currently held for LTO.  */
   lto_clear_user_options ();
-#endif
 
 #ifdef OPTIMIZATION_OPTIONS
   /* Allow default optimizations to be specified on a per-machine basis.  */
   OPTIMIZATION_OPTIONS (optimize, optimize_size);
 #endif
 
-  read_cmdline_options (argc, argv, lang_mask);
+  handle_options (argc, argv, lang_mask);
 
   if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
     {
@@ -1147,12 +1120,6 @@ decode_options (unsigned int argc, const char **argv)
       if (!PARAM_SET_P (PARAM_STACK_FRAME_GROWTH))
         PARAM_VALUE (PARAM_STACK_FRAME_GROWTH) = 40;
     }
-  if (flag_wpa || flag_ltrans)
-    {
-      /* These passes are not WHOPR compatible yet.  */
-      flag_ipa_pta = 0;
-      flag_ipa_struct_reorg = 0;
-    }
 
   if (flag_lto || flag_whopr)
     {
@@ -1487,7 +1454,7 @@ print_specific_help (unsigned int include_flags,
 
 static int
 common_handle_option (size_t scode, const char *arg, int value,
-                     unsigned int lang_mask, int kind ATTRIBUTE_UNUSED)
+                     unsigned int lang_mask)
 {
   static bool verbose = false;
   enum opt_code code = (enum opt_code) scode;
@@ -1790,7 +1757,7 @@ common_handle_option (size_t scode, const char *arg, int value,
       break;
 
     case OPT_fdiagnostics_show_option:
-      global_dc->show_option_requested = value;
+      global_dc->show_option_requested = true;
       break;
 
     case OPT_fdump_:
@@ -2149,10 +2116,6 @@ common_handle_option (size_t scode, const char *arg, int value,
       flag_pedantic_errors = pedantic = 1;
       break;
 
-    case OPT_fwhopr:
-      flag_whopr = value;
-      break;
-
     case OPT_fsee:
     case OPT_fcse_skip_blocks:
     case OPT_floop_optimize:
@@ -2400,10 +2363,8 @@ get_option_state (int option, struct cl_option_state *state)
 /* Set *OPTION according to VALUE and ARG.  */
 
 void
-set_option (int opt_index, int value, const char *arg, int kind)
+set_option (const struct cl_option *option, int value, const char *arg)
 {
-  const struct cl_option *option = &cl_options[opt_index];
-
   if (!option->flag_var)
     return;
 
@@ -2433,9 +2394,6 @@ set_option (int opt_index, int value, const char *arg, int kind)
        *(const char **) option->flag_var = arg;
        break;
     }
-
-  if ((diagnostic_t)kind != DK_UNSPECIFIED)
-    diagnostic_classify_diagnostic (global_dc, opt_index, (diagnostic_t)kind);
 }
 
 
@@ -2479,8 +2437,8 @@ enable_warning_as_error (const char *arg, int value, unsigned int lang_mask)
          const struct cl_option * const option = cl_options + option_index;
 
          /* -Werror=foo implies -Wfoo.  */
-         if (option->var_type == CLVC_BOOLEAN)
-           handle_option (option_index, value, arg, lang_mask, (int)kind);
+         if (option->var_type == CLVC_BOOLEAN && option->flag_var)
+           *(int *) option->flag_var = 1;
 
          if (warning_as_error_callback)
            warning_as_error_callback (option_index);
index af3c6e2..54f57d1 100644 (file)
@@ -103,9 +103,8 @@ extern void prune_options (int *argcp, char ***argvp);
 extern void decode_options (unsigned int argc, const char **argv);
 extern int option_enabled (int opt_idx);
 extern bool get_option_state (int, struct cl_option_state *);
-extern void set_option (int opt_index, int value, const char *arg, int);
-bool handle_option (int opt_index, int value, const char *arg,
-                   unsigned int lang_mask, int kind);
+extern void set_option (const struct cl_option *, int, const char *);
+
 extern void register_warning_as_error_callback (void (*callback) (int));
 extern void enable_warning_as_error (const char *arg, int value,
                                     unsigned int lang_mask);
index a074ef2..8168478 100644 (file)
@@ -1,6 +1,47 @@
-2010-04-07  Iain Sandoe <iains@gcc.gnu.org>
+2010-04-07  Simon Baldwin  <simonb@google.com>
+
+       * gcc.dg/cpp/warn-undef-2.c: New.
+       * gcc.dg/cpp/warn-traditional-2.c: New.
+       * gcc.dg/cpp/warn-comments-2.c: New.
+       * gcc.dg/cpp/warning-directive-1.c: New.
+       * gcc.dg/cpp/warn-long-long.c: New.
+       * gcc.dg/cpp/warn-traditional.c: New.
+       * gcc.dg/cpp/warn-variadic-2.c: New.
+       * gcc.dg/cpp/warn-undef.c: New.
+       * gcc.dg/cpp/warn-normalized-1.c: New.
+       * gcc.dg/cpp/warning-directive-2.c: New.
+       * gcc.dg/cpp/warn-long-long-2.c: New.
+       * gcc.dg/cpp/warn-variadic.c: New.
+       * gcc.dg/cpp/warn-normalized-2.c: New.
+       * gcc.dg/cpp/warning-directive-3.c: New.
+       * gcc.dg/cpp/warn-deprecated-2.c: New.
+       * gcc.dg/cpp/warn-trigraphs-1.c: New.
+       * gcc.dg/cpp/warn-multichar-2.c: New.
+       * gcc.dg/cpp/warn-normalized-3.c: New.
+       * gcc.dg/cpp/warning-directive-4.c: New.
+       * gcc.dg/cpp/warn-unused-macros.c: New.
+       * gcc.dg/cpp/warn-trigraphs-2.c: New.
+       * gcc.dg/cpp/warn-cxx-compat-2.c: New.
+       * gcc.dg/cpp/warn-cxx-compat.c: New.
+       * gcc.dg/cpp/warn-redefined.c: New.
+       * gcc.dg/cpp/warn-trigraphs-3.c: New.
+       * gcc.dg/cpp/warn-unused-macros-2.c: New.
+       * gcc.dg/cpp/warn-deprecated.c: New.
+       * gcc.dg/cpp/warn-trigraphs-4.c: New.
+       * gcc.dg/cpp/warn-redefined-2.c: New.
+       * gcc.dg/cpp/warn-comments.c: New.
+       * gcc.dg/cpp/warn-multichar.c: New.
+       * g++.dg/cpp/warning-directive-1.C: New.
+       * g++.dg/cpp/warning-directive-2.C: New.
+       * g++.dg/cpp/warning-directive-3.C: New.
+       * g++.dg/cpp/warning-directive-4.C: New.
+       * gfortran.dg/warning-directive-1.F90: New.
+       * gfortran.dg/warning-directive-3.F90: New.
+       * gfortran.dg/warning-directive-2.F90: New.
+       * gfortran.dg/warning-directive-4.F90: New.
 
-       PR objc++/23716
+2010-04-07  Iain Sandoe <iains@gcc.gnu.org>
+PR objc++/23716
        * obj-c++.dg/comp-types-10.mm: Remove XFAIL.
 
 2010-04-07  Jason Merrill  <jason@redhat.com>
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-1.C b/gcc/testsuite/g++.dg/cpp/warning-directive-1.C
new file mode 100644 (file)
index 0000000..1ce18c6
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option" }
+
+#warning "Printed"  // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-2.C b/gcc/testsuite/g++.dg/cpp/warning-directive-2.C
new file mode 100644 (file)
index 0000000..abd6427
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option -Werror=cpp" }
+
+#warning "Printed"  // { dg-error "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-3.C b/gcc/testsuite/g++.dg/cpp/warning-directive-3.C
new file mode 100644 (file)
index 0000000..8ed66c6
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option -Werror -Wno-error=cpp" }
+
+#warning "Printed"  // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/g++.dg/cpp/warning-directive-4.C b/gcc/testsuite/g++.dg/cpp/warning-directive-4.C
new file mode 100644 (file)
index 0000000..a5db1b4
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-fdiagnostics-show-option -Wno-cpp" }
+
+#warning "Not printed"  // { dg-bogus "." }
index 17cc9f1..5a17f2b 100644 (file)
@@ -1,7 +1,7 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=comments" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-/* /* */  // { dg-error "\"\.\*\" within comment .-Werror=comments." }
+
+/* /* */  // { dg-error "\"\.\*\" within comment .-Wcomments." }
 
 // \
-          // { dg-error "multi-line comment .-Werror=comments." "multi-line" { target *-*-* } 6 }
+          // { dg-error "multi-line comment .-Wcomments." "multi-line" { target *-*-* } 6 }
index 69c4cfa..6bf7d55 100644 (file)
@@ -1,4 +1,4 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=c++-compat" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#define not !  // { dg-error "identifier \"not\" is a special operator name in C\\+\\+ .-Werror=c\\+\\+-compat." }
+
+#define not !  // { dg-error "identifier \"not\" is a special operator name in C\\+\\+ .-Wc\\+\\+-compat." }
index 8bd608a..b9cfffb 100644 (file)
@@ -1,7 +1,7 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=deprecated" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#assert x(x)  // { dg-error "#assert is a deprecated GCC extension .-Werror=deprecated." }
 
-#if #x(x)     // { dg-error "assertions are a deprecated extension .-Werror=deprecated." }
+#assert x(x)  // { dg-error "#assert is a deprecated GCC extension .-Wdeprecated." }
+
+#if #x(x)     // { dg-error "assertions are a deprecated extension .-Wdeprecated." }
 #endif
index 7b074a3..11eb5fb 100644 (file)
@@ -1,6 +1,6 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Wtraditional -Werror=long-long" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#if 0LL  // { dg-error "traditional C rejects the \"LL\" suffix .-Werror=long-long." }
-         // { dg-error "use of C99 long long integer constant .-Werror=long-long." "use long long" { target *-*-* } 4 }
+
+#if 0LL  // { dg-error "traditional C rejects the \"LL\" suffix .-Wlong-long." }
+         // { dg-error "use of C99 long long integer constant .-Wlong-long." "use long long" { target *-*-* } 4 }
 #endif
index f9fd4f6..31d33bb 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=multichar" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#if 'abc'  // { dg-error "multi-character character constant .-Werror=multichar." }
+
+#if 'abc'  // { dg-error "multi-character character constant .-Wmultichar." }
 #endif
index 24eaea0..380c670 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -fextended-identifiers -Werror=normalized=" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
+
         // { dg-prune-output ".*-Werror=normalized=: Set -Wnormalized=nfc.*" }
-\u0F43  // { dg-error "`.U00000f43' is not in NFC .-Werror=normalized=." }
+\u0F43  // { dg-error "`.U00000f43' is not in NFC .-Wnormalized=." }
index e6b209c..83cc3df 100644 (file)
@@ -1,12 +1,12 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=builtin-macro-redefined" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
+
 #ifndef __TIME__
 #error "__TIME__ builtin is not defined"
 // { dg-bogus "__TIME__ builtin is not defined" "no-time" { target *-*-* } 5 }
 #endif
 
-#define __TIME__ "X"  // { dg-error "\"__TIME__\" redefined .-Werror=builtin-macro-redefined." }
+#define __TIME__ "X"  // { dg-error "\"__TIME__\" redefined .-Wbuiltin-macro-redefined." }
 
 #define __TIME__ "Y"  // { dg-bogus "-Wbuiltin-macro-redefined" }
                       // { dg-warning "\"__TIME__\" redefined" "not-builtin-1" { target *-*-* } 11 }
index 05477af..cb5f690 100644 (file)
@@ -1,23 +1,23 @@
 // { dg-do compile }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=traditional -Wno-deprecated -Wno-long-long" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#assert x(x)         // { dg-error "suggest hiding #assert from traditional C with an indented # .-Werror=traditional." }
 
- #define X X         // { dg-error "traditional C ignores #define with the # indented .-Werror=traditional." }
+#assert x(x)         // { dg-error "suggest hiding #assert from traditional C with an indented # .-Wtraditional." }
+
+ #define X X         // { dg-error "traditional C ignores #define with the # indented .-Wtraditional." }
 
 #if 0
-#elif 1              // { dg-error "suggest not using #elif in traditional C .-Werror=traditional." }
+#elif 1              // { dg-error "suggest not using #elif in traditional C .-Wtraditional." }
 #endif
 
 #define f(X) X
-int f;               // { dg-error "function-like macro \"f\" must be used with arguments in traditional C .-Werror=traditional." }
+int f;               // { dg-error "function-like macro \"f\" must be used with arguments in traditional C .-Wtraditional." }
 
-#if 0U               // { dg-error "traditional C rejects the \"U\" suffix .-Werror=traditional." }
+#if 0U               // { dg-error "traditional C rejects the \"U\" suffix .-Wtraditional." }
 #endif
 
-#if +1               // { dg-error " traditional C rejects the unary plus operator .-Werror=traditional." }
+#if +1               // { dg-error " traditional C rejects the unary plus operator .-Wtraditional." }
 #endif
 
-char *x = "\x0";     // { dg-error "the meaning of '.x' is different in traditional C .-Werror=traditional." }
-char *y = "\a";      // { dg-error "the meaning of '.a' is different in traditional C .-Werror=traditional." }
-char *z = "\u0F43";  // { dg-error "the meaning of '.u' is different in traditional C .-Werror=traditional." }
+char *x = "\x0";     // { dg-error "the meaning of '.x' is different in traditional C .-Wtraditional." }
+char *y = "\a";      // { dg-error "the meaning of '.a' is different in traditional C .-Wtraditional." }
+char *z = "\u0F43";  // { dg-error "the meaning of '.u' is different in traditional C .-Wtraditional." }
index e7537c8..a993e2a 100644 (file)
@@ -1,4 +1,4 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -trigraphs -Werror=trigraphs" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-??=  // { dg-error "trigraph \\?\\?= converted to # .-Werror=trigraphs." }
+
+??=  // { dg-error "trigraph \\?\\?= converted to # .-Wtrigraphs." }
index d8333d4..240ae0f 100644 (file)
@@ -1,4 +1,4 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=trigraphs" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-??=  // { dg-error "trigraph \\?\\?= ignored, use -trigraphs to enable .-Werror=trigraphs." }
+
+??=  // { dg-error "trigraph \\?\\?= ignored, use -trigraphs to enable .-Wtrigraphs." }
index 15fdde9..4eb80e0 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=undef" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#if x  // { dg-error "\"x\" is not defined .-Werror=undef." }
+
+#if x  // { dg-error "\"x\" is not defined .-Wundef." }
 #endif
index d7fe145..58eeebf 100644 (file)
@@ -1,4 +1,4 @@
 // { dg-do preprocess }
 // { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=unused-macros" }
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#define X X  // { dg-error "macro \"X\" is not used .-Werror=unused-macros." }
+
+#define X X  // { dg-error "macro \"X\" is not used .-Wunused-macros." }
index 1a266cd..f43d96a 100644 (file)
@@ -1,6 +1,6 @@
 /* { dg-do preprocess } */
 /* { dg-options "-ansi -fdiagnostics-show-option -pedantic -Werror=variadic-macros" } */
-/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
-#define F(...) X   /* { dg-error "anonymous variadic macros were introduced in C99 .-Werror=variadic-macros." } */
 
-#define G(X...) X  /* { dg-error "ISO C does not permit named variadic macros .-Werror=variadic-macros." } */
+#define F(...) X   /* { dg-error "anonymous variadic macros were introduced in C99 .-Wvariadic-macros." } */
+
+#define G(X...) X  /* { dg-error "ISO C does not permit named variadic macros .-Wvariadic-macros." } */
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-1.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-1.c
new file mode 100644 (file)
index 0000000..cb4bd32
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option" }
+
+#warning "Printed"  // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-2.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-2.c
new file mode 100644 (file)
index 0000000..0889803
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=cpp" }
+
+#warning "Printed"  // { dg-error "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-3.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-3.c
new file mode 100644 (file)
index 0000000..48c97f3
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror -Wno-error=cpp" }
+
+#warning "Printed"  // { dg-warning "\"Printed\" .-Wcpp." }
diff --git a/gcc/testsuite/gcc.dg/cpp/warning-directive-4.c b/gcc/testsuite/gcc.dg/cpp/warning-directive-4.c
new file mode 100644 (file)
index 0000000..2eb1017
--- /dev/null
@@ -0,0 +1,4 @@
+// { dg-do preprocess }
+// { dg-options "-std=gnu99 -fdiagnostics-show-option -Wno-cpp" }
+
+#warning "Not printed"  // { dg-bogus "." }
index fa9460a..75b78bf 100644 (file)
@@ -1,5 +1,5 @@
 ! { dg-do preprocess }
 ! { dg-options "-std=f95 -fdiagnostics-show-option -Werror=cpp" }
-! { dg-warning "some warnings being treated as errors" "" {target "*-*-*"} 0 } 
+
 #warning "Printed"
-! { dg-error "\"Printed\" .-Werror=cpp." "" { target *-*-* } 4 }
+! { dg-error "\"Printed\" .-Wcpp." "" { target *-*-* } 4 }
index b55d255..7762099 100644 (file)
@@ -1,3 +1,45 @@
+2010-04-07  Simon Baldwin  <simonb@google.com>
+
+       * directives.c (do_diagnostic): Add warning reason argument,
+       call appropriate error reporting function for code.
+       (directive_diagnostics): Call specific warning functions with
+       warning reason where appropriate.
+       (do_error, do_warning, do_pragma_dependency): Add warning reason
+       argument to do_diagnostic calls.
+       * macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
+       _cpp_create_definition): Call specific warning functions with
+       warning reason where appropriate.
+       * Makefile.in: Add new diagnostic functions to gettext translations.
+       * include/cpplib.h (struct cpp_callbacks): Add warning reason code
+       to error callback.
+       (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
+       CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
+       (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
+       CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
+       CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
+       CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
+       CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
+       CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
+       CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
+       warning reason codes.
+       (cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
+       cpp_warning_with_line, cpp_pedwarning_with_line,
+       cpp_warning_with_line_syshdr): New specific error reporting functions.
+       * pch.c (cpp_valid_state): Call specific warning functions with
+       warning reason where appropriate.
+       * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
+       diagnostic handlers.
+       (cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
+       cpp_warning_with_line, cpp_pedwarning_with_line,
+       cpp_warning_with_line_syshdr): New specific error reporting functions.
+       * expr.c (cpp_classify_number, eval_token, num_unary_op): Call
+       specific warning functions with warning reason where appropriate.
+       * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
+       warn_about_normalization, lex_identifier_intern, lex_identifier,
+       _cpp_lex_direct): Ditto.
+       * charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
+       narrow_str_to_charconst): Ditto.
+
 2010-04-06  Jakub Jelinek  <jakub@redhat.com>
 
        PR preprocessor/43642
index f299982..f628272 100644 (file)
@@ -301,14 +301,16 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment)
              && (!in_comment || warn_in_comment (pfile, note)))
            {
              if (CPP_OPTION (pfile, trigraphs))
-               cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col,
-                                    "trigraph ??%c converted to %c",
-                                    note->type,
-                                    (int) _cpp_trigraph_map[note->type]);
+               cpp_warning_with_line (pfile, CPP_W_TRIGRAPHS,
+                                       pfile->line_table->highest_line, col,
+                                      "trigraph ??%c converted to %c",
+                                      note->type,
+                                      (int) _cpp_trigraph_map[note->type]);
              else
                {
-                 cpp_error_with_line 
-                   (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col,
+                 cpp_warning_with_line 
+                   (pfile, CPP_W_TRIGRAPHS,
+                     pfile->line_table->highest_line, col,
                     "trigraph ??%c ignored, use -trigraphs to enable",
                     note->type);
                }
@@ -355,9 +357,10 @@ _cpp_skip_block_comment (cpp_reader *pfile)
              && cur[0] == '*' && cur[1] != '/')
            {
              buffer->cur = cur;
-             cpp_error_with_line (pfile, CPP_DL_WARNING,
-                                  pfile->line_table->highest_line, CPP_BUF_COL (buffer),
-                                  "\"/*\" within comment");
+             cpp_warning_with_line (pfile, CPP_W_COMMENTS,
+                                    pfile->line_table->highest_line,
+                                    CPP_BUF_COL (buffer),
+                                    "\"/*\" within comment");
            }
        }
       else if (c == '\n')
@@ -460,11 +463,11 @@ warn_about_normalization (cpp_reader *pfile,
 
       sz = cpp_spell_token (pfile, token, buf, false) - buf;
       if (NORMALIZE_STATE_RESULT (s) == normalized_C)
-       cpp_error_with_line (pfile, CPP_DL_WARNING, token->src_loc, 0,
-                            "`%.*s' is not in NFKC", (int) sz, buf);
+       cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
+                              "`%.*s' is not in NFKC", (int) sz, buf);
       else
-       cpp_error_with_line (pfile, CPP_DL_WARNING, token->src_loc, 0,
-                            "`%.*s' is not in NFC", (int) sz, buf);
+       cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
+                              "`%.*s' is not in NFC", (int) sz, buf);
     }
 }
 
@@ -545,9 +548,9 @@ lex_identifier_intern (cpp_reader *pfile, const uchar *base)
 
       /* For -Wc++-compat, warn about use of C++ named operators.  */
       if (result->flags & NODE_WARN_OPERATOR)
-       cpp_error (pfile, CPP_DL_WARNING,
-                  "identifier \"%s\" is a special operator name in C++",
-                  NODE_NAME (result));
+       cpp_warning (pfile, CPP_W_CXX_OPERATOR_NAMES,
+                    "identifier \"%s\" is a special operator name in C++",
+                    NODE_NAME (result));
     }
 
   return result;
@@ -622,9 +625,9 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn,
 
       /* For -Wc++-compat, warn about use of C++ named operators.  */
       if (result->flags & NODE_WARN_OPERATOR)
-       cpp_error (pfile, CPP_DL_WARNING,
-                  "identifier \"%s\" is a special operator name in C++",
-                  NODE_NAME (result));
+       cpp_warning (pfile, CPP_W_CXX_OPERATOR_NAMES,
+                    "identifier \"%s\" is a special operator name in C++",
+                    NODE_NAME (result));
     }
 
   return result;
@@ -1531,7 +1534,7 @@ _cpp_lex_direct (cpp_reader *pfile)
            }
 
          if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments))
-           cpp_error (pfile, CPP_DL_WARNING, "multi-line comment");
+           cpp_warning (pfile, CPP_W_COMMENTS, "multi-line comment");
        }
       else if (c == '=')
        {