This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR 42966 add some indication that a warning has been converted to an error


With -fdiagnostics-show-option, this patch adds [-Werror=option] to
warnings converted to errors. For default warnings (those not assigned
to any option), it adds [enabled by default]. For default warnings
converted to errors it adds [-Werror]. For warnings not converted to
errors, the output remains the same, that is, [-Woption].

This is a low impact patch, and -fdiagnostics-show-option is disabled
by default, so I think it should be pretty safe to commit for 4.5.

OK for 4.5? or 4.6?

2010-02-26  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR 42966
	* diagnostics.c (diagnostic_report_diagnostic): Mark specially
	warnings converted to errors.
Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c	(revision 156927)
+++ gcc/diagnostic.c	(working copy)
@@ -306,10 +306,11 @@ diagnostic_classify_diagnostic (diagnost
 bool
 diagnostic_report_diagnostic (diagnostic_context *context,
 			      diagnostic_info *diagnostic)
 {
   location_t location = diagnostic->location;
+  diagnostic_t orig_diag_kind = diagnostic->kind;
   bool maybe_print_warnings_as_errors_message = false;
   const char *saved_format_spec;
 
   /* Give preference to being able to inhibit warnings, before they
      get reclassified to something else.  */
@@ -405,15 +406,45 @@ diagnostic_report_diagnostic (diagnostic
 				    diagnostic->message.args_ptr);
     }
   ++diagnostic_kind_count (context, diagnostic->kind);
 
   saved_format_spec = diagnostic->message.format_spec;
-  if (context->show_option_requested && diagnostic->option_index)
-    diagnostic->message.format_spec
-      = ACONCAT ((diagnostic->message.format_spec,
-                  " [", cl_options[diagnostic->option_index].opt_text, "]", NULL));
+  if (context->show_option_requested)
+    {
+      const char * option_text = NULL;
 
+      if (diagnostic->option_index)
+	{
+	  /* A warning classified as an error.  */
+	  if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
+	      && diagnostic->kind == DK_ERROR)
+	    option_text 
+	      = ACONCAT ((cl_options[OPT_Werror_].opt_text,
+			  /* Skip over "-W".  */
+			  cl_options[diagnostic->option_index].opt_text + 2,
+			  NULL));
+	  /* A warning with option.  */
+	  else
+	    option_text = cl_options[diagnostic->option_index].opt_text;
+	}
+      /* A warning without option classified as an error.  */
+      else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
+	       || diagnostic->kind == DK_WARNING)
+	{
+	  if (context->warning_as_error_requested)
+	    option_text = cl_options[OPT_Werror].opt_text;
+	  else
+	    option_text = _("enabled by default");
+	}
+
+      if (option_text)
+	diagnostic->message.format_spec
+	  = ACONCAT ((diagnostic->message.format_spec,
+		      " ", 
+		      "[", option_text, "]",
+		      NULL));
+    }
   diagnostic->message.locus = &diagnostic->location;
   diagnostic->message.abstract_origin = &diagnostic->abstract_origin;
   diagnostic->abstract_origin = NULL;
   pp_format (context->printer, &diagnostic->message);
   (*diagnostic_starter (context)) (context, diagnostic);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]