+ /* If the user requested that warnings be treated as errors, so be
+ it. Note that we do this before the next block so that
+ individual warnings can be overridden back to warnings with
+ -Wno-error=*. */
+ if (context->warning_as_error_requested
+ && diagnostic->kind == DK_WARNING)
+ {
+ diagnostic->kind = DK_ERROR;
+ }
+
+ if (diagnostic->option_index)
+ {
+ /* This tests if the user provided the appropriate -Wfoo or
+ -Wno-foo option. */
+ if (! option_enabled (diagnostic->option_index))
+ return false;
+ /* This tests if the user provided the appropriate -Werror=foo
+ option. */
+ if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
+ {
+ diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
+ }
+ /* This allows for future extensions, like temporarily disabling
+ warnings for ranges of source code. */
+ if (diagnostic->kind == DK_IGNORED)
+ return false;
+ }
+
+ if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
+ context->some_warnings_are_errors = true;
+
+ context->lock++;
+
+ if (diagnostic->kind == DK_ICE && plugins_active_p ())
+ {
+ fnotice (stderr, "*** WARNING *** there are active plugins, do not report"
+ " this as a bug unless you can reproduce it without enabling"
+ " any plugins.\n");
+ dump_active_plugins (stderr);
+ }
+
+ if (diagnostic->kind == DK_ICE)
+ {
+#ifndef ENABLE_CHECKING
+ /* When not checking, ICEs are converted to fatal errors when an
+ error has already occurred. This is counteracted by
+ abort_on_error. */
+ if ((diagnostic_kind_count (context, DK_ERROR) > 0
+ || diagnostic_kind_count (context, DK_SORRY) > 0)
+ && !context->abort_on_error)
+ {
+ expanded_location s = expand_location (diagnostic->location);
+ fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
+ s.file, s.line);
+ exit (ICE_EXIT_CODE);
+ }
+#endif
+ if (context->internal_error)
+ (*context->internal_error) (diagnostic->message.format_spec,
+ diagnostic->message.args_ptr);
+ }
+ ++diagnostic_kind_count (context, diagnostic->kind);
+
+ saved_format_spec = diagnostic->message.format_spec;
+ 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.x_data = &diagnostic->x_data;
+ diagnostic->x_data = NULL;
+ pp_format (context->printer, &diagnostic->message);
+ (*diagnostic_starter (context)) (context, diagnostic);
+ pp_output_formatted_text (context->printer);
+ (*diagnostic_finalizer (context)) (context, diagnostic);
+ pp_flush (context->printer);
+ diagnostic_action_after_output (context, diagnostic);
+ diagnostic->message.format_spec = saved_format_spec;
+ diagnostic->x_data = NULL;
+