re PR other/42965 (no "warnings being treated as errors" for individual -Werror=x options)

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

	PR 42965
	* diagnostic.c (diagnostic_initialize): Initialize
	some_warnings_are_errors.
	(diagnostic_finish): New.
	(diagnostic_action_after_output): Call it before exiting.
	(diagnostic_report_diagnostic): Do not print message here. Set
	some_warnings_are_errors.
	* diagnostic.h (diagnostic_context): Delete
	issue_warnings_are_errors_message. Add some_warnings_are_errors.
	(diagnostic_finish): Declare.
	* toplev.c (toplev_main): Call it before exit.
testsuite/
	* gcc.dg/Werror-6.c: Adjust.
	* gcc.dg/Werror-implicit-function-declaration.c: Likewise.
	* gcc.dg/Werror-4.c: Likewise.
	* gcc.dg/Wdeclaration-after-statement-3.c: Likewise.
	* gcc.dg/Wswitch-enum-error.c: Likewise.
	* gcc.dg/Wpointer-arith.c: Likewise.
	* gcc.dg/Wfatal.c: Likewise.
	* gcc.dg/Wswitch-error.c: Likewise.
	* g++.dg/warn/unused-result1-Werror.c: Likewise.
	* gcc.dg/Werror-9.c: Delete. Duplicate of Werror-4.c.
	* gcc.dg/cpp/warn-undef-2.c: Likewise.
	* gcc.dg/cpp/warn-traditional-2.c: Likewise.
	* gcc.dg/cpp/warn-comments-2.c: Likewise.
	* gcc.dg/cpp/warn-variadic-2.c: Likewise.
	* gcc.dg/cpp/warning-directive-2.c: Likewise.
	* gcc.dg/cpp/warn-long-long-2.c: Likewise.
	* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
	* gcc.dg/cpp/warn-multichar-2.c: Likewise.
	* gcc.dg/cpp/warn-normalized-3.c: Likewise.
	* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
	* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
	* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
	* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
	* gcc.dg/cpp/warn-redefined-2.c: Likewise.
	* g++.dg/cpp/warning-directive-2.C: Likewise.
	* gfortran.dg/warning-directive-2.F90: Likewise.

From-SVN: r158168
This commit is contained in:
Manuel López-Ibáñez 2010-04-09 15:45:52 +00:00
parent cb6addf4a6
commit d0b8780d9f
31 changed files with 109 additions and 57 deletions

View File

@ -1,3 +1,17 @@
2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 42965
* diagnostic.c (diagnostic_initialize): Initialize
some_warnings_are_errors.
(diagnostic_finish): New.
(diagnostic_action_after_output): Call it before exiting.
(diagnostic_report_diagnostic): Do not print message here. Set
some_warnings_are_errors.
* diagnostic.h (diagnostic_context): Delete
issue_warnings_are_errors_message. Add some_warnings_are_errors.
(diagnostic_finish): Declare.
* toplev.c (toplev_main): Call it before exit.
2010-04-09 Jason Merrill <jason@redhat.com>
PR c++/42623

View File

@ -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++;

View File

@ -69,7 +69,7 @@ struct diagnostic_context
/* True if we should display the "warnings are being tread as error"
message, usually displayed once per compiler run. */
bool issue_warnings_are_errors_message;
bool some_warnings_are_errors;
/* True if it has been requested that warnings be treated as errors. */
bool warning_as_error_requested;
@ -206,6 +206,7 @@ extern diagnostic_context *global_dc;
/* Diagnostic related functions. */
extern void diagnostic_initialize (diagnostic_context *);
extern void diagnostic_finish (diagnostic_context *);
extern void diagnostic_report_current_module (diagnostic_context *);
extern void diagnostic_report_current_function (diagnostic_context *,
diagnostic_info *);

View File

@ -1,3 +1,33 @@
2010-04-09 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 42965
* gcc.dg/Werror-6.c: Adjust.
* gcc.dg/Werror-implicit-function-declaration.c: Likewise.
* gcc.dg/Werror-4.c: Likewise.
* gcc.dg/Wdeclaration-after-statement-3.c: Likewise.
* gcc.dg/Wswitch-enum-error.c: Likewise.
* gcc.dg/Wpointer-arith.c: Likewise.
* gcc.dg/Wfatal.c: Likewise.
* gcc.dg/Wswitch-error.c: Likewise.
* g++.dg/warn/unused-result1-Werror.c: Likewise.
* gcc.dg/Werror-9.c: Delete. Duplicate of Werror-4.c.
* gcc.dg/cpp/warn-undef-2.c: Likewise.
* gcc.dg/cpp/warn-traditional-2.c: Likewise.
* gcc.dg/cpp/warn-comments-2.c: Likewise.
* gcc.dg/cpp/warn-variadic-2.c: Likewise.
* gcc.dg/cpp/warning-directive-2.c: Likewise.
* gcc.dg/cpp/warn-long-long-2.c: Likewise.
* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
* gcc.dg/cpp/warn-multichar-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-3.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
* gcc.dg/cpp/warn-redefined-2.c: Likewise.
* g++.dg/cpp/warning-directive-2.C: Likewise.
* gfortran.dg/warning-directive-2.F90: Likewise.
2010-04-09 Jason Merrill <jason@redhat.com>
PR c++/42623

View File

@ -1,4 +1,4 @@
// { dg-do preprocess }
// { dg-options "-fdiagnostics-show-option -Werror=cpp" }
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
#warning "Printed" // { dg-error "\"Printed\" .-Wcpp." }

View File

@ -1,5 +1,6 @@
// PR 40614
// { dg-options "-Werror=unused-result" }
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
class QByteArray {
public:
QByteArray(const QByteArray &);

View File

@ -1,7 +1,7 @@
/* PR 35058: -Werror= works only with some warnings. */
/* { dg-do compile } */
/* { dg-options "-std=c99 -pedantic -Werror=declaration-after-statement" } */
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
extern void abort (void);
extern void exit (int);

View File

@ -1,17 +1,17 @@
/* { dg-do compile } */
/* { dg-options "-Wattributes" } */
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
/* Make sure the pragma enables the error. */
#pragma GCC diagnostic error "-Waddress"
void __attribute__((dj)) bar() { } /* { dg-warning ".* attribute directive ignored" } */
void __attribute__((dj)) bar() { } /* { dg-warning "attribute directive ignored" } */
int i;
void
foo ()
{
if (&i) /* { dg-error ".* will always evaluate as 'true'" } */
if (&i) /* { dg-error "will always evaluate as 'true'" } */
grill ();
}

View File

@ -1,7 +1,7 @@
/* { dg-do compile } */
/* { dg-options "-Wattributes -Werror=address" } */
/* Make sure -Werror-foo emits an error and not a warning */
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
/* Make sure -Werror=foo emits an error and not a warning */
void __attribute__((dj)) bar() { } /* { dg-warning ".* attribute directive ignored" } */

View File

@ -1,17 +0,0 @@
/* { dg-do compile } */
/* { dg-options "-Wattributes" } */
/* Make sure #pragma can enable a warning as an error. */
#pragma GCC diagnostic error "-Waddress"
void __attribute__((dj)) bar() { } /* { dg-warning ".* attribute directive ignored" } */
int i;
void
foo ()
{
if (&i) /* { dg-error ".* will always evaluate as 'true'" } */
grill ();
}

View File

@ -1,6 +1,7 @@
/* Test the legacy option -Werror-implicit-function-declaration */
/* { dg-do compile } */
/* { dg-options "-std=c89 -Werror-implicit-function-declaration" } */
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
void f(void)
{
puts("Hello"); /* { dg-error "implicit declaration of function" } */

View File

@ -5,6 +5,7 @@
int i = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */
int k = 1 / 0; /* { dg-error "division by zero" } */
int j = INT_MIN - 1;
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
/* { dg-message "terminated due to -Wfatal-errors" "" { target *-*-* } 0 } */

View File

@ -8,3 +8,4 @@ void *test(){
if(a) a++; /* { dg-error "wrong type argument to increment" } */
return a+x; /* { dg-error "pointer of type" } */
}
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */

View File

@ -1,7 +1,7 @@
/* { dg-do compile } */
/* { dg-options "-Werror=switch-enum -Wswitch" } */
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
enum e { e1, e2 };
int

View File

@ -61,3 +61,4 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
}
return 0;
}
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */

View File

@ -1,6 +1,6 @@
// { 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 .-Wcomments." }
// \

View 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\\+\\+ .-Wc\\+\\+-compat." }

View File

@ -1,6 +1,6 @@
// { 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 .-Wdeprecated." }
#if #x(x) // { dg-error "assertions are a deprecated extension .-Wdeprecated." }

View 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 .-Wlong-long." }
// { dg-error "use of C99 long long integer constant .-Wlong-long." "use long long" { target *-*-* } 4 }
#endif

View 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 .-Wmultichar." }
#endif

View 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 .-Wnormalized=." }

View File

@ -1,6 +1,6 @@
// { 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 }

View File

@ -1,6 +1,6 @@
// { 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 # .-Wtraditional." }
#define X X // { dg-error "traditional C ignores #define with the # indented .-Wtraditional." }

View 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 # .-Wtrigraphs." }

View 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 .-Wtrigraphs." }

View 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 .-Wundef." }
#endif

View 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 .-Wunused-macros." }

View 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 .-Wvariadic-macros." } */
#define G(X...) X /* { dg-error "ISO C does not permit named variadic macros .-Wvariadic-macros." } */

View File

@ -1,4 +1,4 @@
// { dg-do preprocess }
// { dg-options "-std=gnu99 -fdiagnostics-show-option -Werror=cpp" }
/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */
#warning "Printed" // { dg-error "\"Printed\" .-Wcpp." }

View 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\" .-Wcpp." "" { target *-*-* } 4 }

View File

@ -2466,6 +2466,7 @@ toplev_main (int argc, char **argv)
if (warningcount || errorcount)
print_ignored_options ();
diagnostic_finish (global_dc);
/* Invoke registered plugin callbacks if any. */
invoke_plugin_callbacks (PLUGIN_FINISH, NULL);