summaryrefslogtreecommitdiff
path: root/gcc/diagnostic.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r--gcc/diagnostic.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 791deacd636..5df458b465e 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -97,7 +97,7 @@ diagnostic_initialize (diagnostic_context *context)
context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
- context->issue_warnings_are_errors_message = true;
+ context->some_warnings_are_errors = false;
context->warning_as_error_requested = false;
memset (context->classify_diagnostic, DK_UNSPECIFIED,
sizeof context->classify_diagnostic);
@@ -112,6 +112,28 @@ diagnostic_initialize (diagnostic_context *context)
context->inhibit_notes_p = false;
}
+/* Do any cleaning up required after the last diagnostic is emitted. */
+
+void
+diagnostic_finish (diagnostic_context *context)
+{
+ /* Some of the errors may actually have been warnings. */
+ if (context->some_warnings_are_errors)
+ {
+ /* -Werror was given. */
+ if (context->warning_as_error_requested)
+ pp_verbatim (context->printer,
+ _("%s: all warnings being treated as errors\n"),
+ progname);
+ /* At least one -Werror= was given. */
+ else
+ pp_verbatim (context->printer,
+ _("%s: some warnings being treated as errors\n"),
+ progname);
+ pp_flush (context->printer);
+ }
+}
+
/* Initialize DIAGNOSTIC, where the message MSG has already been
translated. */
void
@@ -184,6 +206,7 @@ diagnostic_action_after_output (diagnostic_context *context,
if (flag_fatal_errors)
{
fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
+ diagnostic_finish (context);
exit (FATAL_EXIT_CODE);
}
break;
@@ -200,7 +223,7 @@ diagnostic_action_after_output (diagnostic_context *context,
case DK_FATAL:
if (context->abort_on_error)
real_abort ();
-
+ diagnostic_finish (context);
fnotice (stderr, "compilation terminated.\n");
exit (FATAL_EXIT_CODE);
@@ -309,7 +332,7 @@ diagnostic_report_diagnostic (diagnostic_context *context,
diagnostic_info *diagnostic)
{
location_t location = diagnostic->location;
- bool maybe_print_warnings_as_errors_message = false;
+ diagnostic_t orig_diag_kind = diagnostic->kind;
const char *saved_format_spec;
/* Give preference to being able to inhibit warnings, before they
@@ -319,7 +342,11 @@ diagnostic_report_diagnostic (diagnostic_context *context,
return false;
if (diagnostic->kind == DK_PEDWARN)
- diagnostic->kind = pedantic_warning_kind ();
+ {
+ diagnostic->kind = pedantic_warning_kind ();
+ /* We do this to avoid giving the message for -pedantic-errors. */
+ orig_diag_kind = diagnostic->kind;
+ }
if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
return false;
@@ -343,7 +370,6 @@ diagnostic_report_diagnostic (diagnostic_context *context,
&& diagnostic->kind == DK_WARNING)
{
diagnostic->kind = DK_ERROR;
- maybe_print_warnings_as_errors_message = true;
}
if (diagnostic->option_index)
@@ -357,7 +383,6 @@ diagnostic_report_diagnostic (diagnostic_context *context,
if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
{
diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
- maybe_print_warnings_as_errors_message = false;
}
/* This allows for future extensions, like temporarily disabling
warnings for ranges of source code. */
@@ -365,15 +390,8 @@ diagnostic_report_diagnostic (diagnostic_context *context,
return false;
}
- /* If we changed the kind due to -Werror, and didn't override it, we
- need to print this message. */
- if (context->issue_warnings_are_errors_message
- && maybe_print_warnings_as_errors_message)
- {
- pp_verbatim (context->printer,
- "%s: warnings being treated as errors\n", progname);
- context->issue_warnings_are_errors_message = false;
- }
+ if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
+ context->some_warnings_are_errors = true;
context->lock++;