mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 02:03:03 +00:00
diagnostics: "-Werror -Wno-error=foo" must not emit errors
Currently "-Werror -Wno-error=foo" still turns "foo" warnings into errors. Reported by Alexandre Duret-Lutz. See http://lists.gnu.org/archive/html/bug-bison/2013-09/msg00015.html. * src/complain.c (errority, errority_flag): New. (complain_init): Initialize the latter. (warning_argmatch): Extract the loop iterating on the flag's bits. Set and unset errority_flag here. (warnings_argmatch): -Wno-error is not the same as -Wno-error=everything: we must remember if category foo was explicitly turned in an error/warning via -W(no-)error=foo. (warning_severity): Use errority_flag. * tests/input.at (Symbols): Just check --yacc, not -Wyacc, that's the job of tests on -W. (-Werror is not affected by -Wnone and -Wall): Rename as... (-Werror combinations): this. Tests more combinations of -W, -W(no-)error, and -W(no-)error=foo. * tests/local.at (AT_BISON_CHECK_WARNINGS): Don't expect -Werror to turn runs that issue warnings into runs with errors, as the warnings might be enforced as warnings by -Wno-error=foo, in which case -Werror does not change anything. * doc/bison.texi (Bison Options): Try to be clearer about how -W(no-)error and -W(no-)error=foo interact.
This commit is contained in:
11
NEWS
11
NEWS
@@ -4,7 +4,16 @@ GNU Bison NEWS
|
|||||||
|
|
||||||
** Bug fixes
|
** Bug fixes
|
||||||
|
|
||||||
Portability issues in the test suite.
|
*** Portability issues in the test suite.
|
||||||
|
|
||||||
|
*** Fixes of the -Werror option
|
||||||
|
|
||||||
|
Options such as "-Werror -Wno-error=foo" were still turning "foo"
|
||||||
|
diagnostics into errors instead of warnings. This is fixed.
|
||||||
|
|
||||||
|
Actually, for consistency with GCC, "-Wno-error=foo -Werror" now also
|
||||||
|
leaves "foo" diagnostics as warnings. Similarly, with "-Werror=foo
|
||||||
|
-Wno-error", "foo" diagnostics are now errors.
|
||||||
|
|
||||||
* Noteworthy changes in release 3.0 (2013-07-25) [stable]
|
* Noteworthy changes in release 3.0 (2013-07-25) [stable]
|
||||||
|
|
||||||
|
|||||||
@@ -10065,18 +10065,16 @@ A category can be turned off by prefixing its name with @samp{no-}. For
|
|||||||
instance, @option{-Wno-yacc} will hide the warnings about
|
instance, @option{-Wno-yacc} will hide the warnings about
|
||||||
POSIX Yacc incompatibilities.
|
POSIX Yacc incompatibilities.
|
||||||
|
|
||||||
@item -Werror[=@var{category}]
|
@item -Werror
|
||||||
@itemx -Wno-error[=@var{category}]
|
Turn enabled warnings for every @var{category} into errors, unless they are
|
||||||
Enable warnings falling in @var{category}, and treat them as errors. If no
|
explicitly disabled by @option{-Wno-error=@var{category}}.
|
||||||
@var{category} is given, it defaults to making all enabled warnings into errors.
|
|
||||||
|
@item -Werror=@var{category}
|
||||||
|
Enable warnings falling in @var{category}, and treat them as errors.
|
||||||
|
|
||||||
@var{category} is the same as for @option{--warnings}, with the exception that
|
@var{category} is the same as for @option{--warnings}, with the exception that
|
||||||
it may not be prefixed with @samp{no-} (see above).
|
it may not be prefixed with @samp{no-} (see above).
|
||||||
|
|
||||||
Prefixed with @samp{no}, it deactivates the error treatment for this
|
|
||||||
@var{category}. However, the warning itself won't be disabled, or enabled, by
|
|
||||||
this option.
|
|
||||||
|
|
||||||
Note that the precedence of the @samp{=} and @samp{,} operators is such that
|
Note that the precedence of the @samp{=} and @samp{,} operators is such that
|
||||||
the following commands are @emph{not} equivalent, as the first will not treat
|
the following commands are @emph{not} equivalent, as the first will not treat
|
||||||
S/R conflicts as errors.
|
S/R conflicts as errors.
|
||||||
@@ -10086,6 +10084,14 @@ $ bison -Werror=yacc,conflicts-sr input.y
|
|||||||
$ bison -Werror=yacc,error=conflicts-sr input.y
|
$ bison -Werror=yacc,error=conflicts-sr input.y
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
@item -Wno-error
|
||||||
|
Do not turn enabled warnings for every @var{category} into errors, unless
|
||||||
|
they are explicitly enabled by @option{-Werror=@var{category}}.
|
||||||
|
|
||||||
|
@item -Wno-error=@var{category}
|
||||||
|
Deactivate the error treatment for this @var{category}. However, the warning
|
||||||
|
itself won't be disabled, or enabled, by this option.
|
||||||
|
|
||||||
@item -f [@var{feature}]
|
@item -f [@var{feature}]
|
||||||
@itemx --feature[=@var{feature}]
|
@itemx --feature[=@var{feature}]
|
||||||
Activate miscellaneous @var{feature}. @var{feature} can be one of:
|
Activate miscellaneous @var{feature}. @var{feature} can be one of:
|
||||||
|
|||||||
@@ -35,6 +35,17 @@ err_status complaint_status = status_none;
|
|||||||
|
|
||||||
bool warnings_are_errors = false;
|
bool warnings_are_errors = false;
|
||||||
|
|
||||||
|
/** Whether -Werror/-Wno-error was applied to a warning. */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
errority_unset = 0, /** No explict status. */
|
||||||
|
errority_disabled = 1, /** Explictly disabled with -Wno-error=foo. */
|
||||||
|
errority_enabled = 2 /** Explictly enabled with -Werror=foo. */
|
||||||
|
} errority;
|
||||||
|
|
||||||
|
/** For each warning type, its errority. */
|
||||||
|
static errority errority_flag[warnings_size];
|
||||||
|
|
||||||
/** Diagnostics severity. */
|
/** Diagnostics severity. */
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@@ -103,32 +114,26 @@ warning_argmatch (char const *arg, size_t no, size_t err)
|
|||||||
no = !no;
|
no = !no;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no)
|
size_t b;
|
||||||
{
|
for (b = 0; b < warnings_size; ++b)
|
||||||
size_t b;
|
if (value & 1 << b)
|
||||||
for (b = 0; b < warnings_size; ++b)
|
{
|
||||||
if (value & 1 << b)
|
if (err && no)
|
||||||
|
/* -Wno-error=foo. */
|
||||||
|
errority_flag[b] = errority_disabled;
|
||||||
|
else if (err && !no)
|
||||||
{
|
{
|
||||||
if (err)
|
/* -Werror=foo: enables -Wfoo. */
|
||||||
{
|
errority_flag[b] = errority_enabled;
|
||||||
/* -Wno-error=foo: if foo enabled as an error,
|
warnings_flag[b] = severity_warning;
|
||||||
make it a warning. */
|
|
||||||
if (warnings_flag[b] == severity_error)
|
|
||||||
warnings_flag[b] = severity_warning;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
/* -Wno-foo. */
|
|
||||||
warnings_flag[b] = severity_disabled;
|
|
||||||
}
|
}
|
||||||
}
|
else if (no)
|
||||||
else
|
/* -Wno-foo. */
|
||||||
{
|
warnings_flag[b] = severity_disabled;
|
||||||
size_t b;
|
else
|
||||||
for (b = 0; b < warnings_size; ++b)
|
/* -Wfoo. */
|
||||||
if (value & 1 << b)
|
warnings_flag[b] = severity_warning;
|
||||||
/* -Wfoo and -Werror=foo. */
|
}
|
||||||
warnings_flag[b] = err ? severity_error : severity_warning;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Decode a comma-separated list of arguments from -W.
|
/** Decode a comma-separated list of arguments from -W.
|
||||||
@@ -145,10 +150,7 @@ warnings_argmatch (char *args)
|
|||||||
if (STREQ (args, "error"))
|
if (STREQ (args, "error"))
|
||||||
warnings_are_errors = true;
|
warnings_are_errors = true;
|
||||||
else if (STREQ (args, "no-error"))
|
else if (STREQ (args, "no-error"))
|
||||||
{
|
warnings_are_errors = false;
|
||||||
warnings_are_errors = false;
|
|
||||||
warning_argmatch ("no-error=everything", 3, 6);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The length of the possible 'no-' prefix: 3, or 0.
|
// The length of the possible 'no-' prefix: 3, or 0.
|
||||||
@@ -176,27 +178,46 @@ complain_init (void)
|
|||||||
|
|
||||||
size_t b;
|
size_t b;
|
||||||
for (b = 0; b < warnings_size; ++b)
|
for (b = 0; b < warnings_size; ++b)
|
||||||
warnings_flag[b] = (1 << b & warnings_default
|
{
|
||||||
? severity_warning
|
warnings_flag[b] = (1 << b & warnings_default
|
||||||
: severity_unset);
|
? severity_warning
|
||||||
|
: severity_unset);
|
||||||
|
errority_flag[b] = errority_unset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* A diagnostic with FLAGS is about to be issued. With what severity?
|
||||||
|
(severity_fatal, severity_error, severity_disabled, or
|
||||||
|
severity_warning.) */
|
||||||
|
|
||||||
static severity
|
static severity
|
||||||
warning_severity (warnings flags)
|
warning_severity (warnings flags)
|
||||||
{
|
{
|
||||||
if (flags & fatal)
|
if (flags & fatal)
|
||||||
|
/* Diagnostics about fatal errors. */
|
||||||
return severity_fatal;
|
return severity_fatal;
|
||||||
else if (flags & complaint)
|
else if (flags & complaint)
|
||||||
|
/* Diagnostics about errors. */
|
||||||
return severity_error;
|
return severity_error;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Diagnostics about warnings. */
|
||||||
severity res = severity_disabled;
|
severity res = severity_disabled;
|
||||||
size_t b;
|
size_t b;
|
||||||
for (b = 0; b < warnings_size; ++b)
|
for (b = 0; b < warnings_size; ++b)
|
||||||
if (flags & 1 << b)
|
if (flags & 1 << b)
|
||||||
res = res < warnings_flag[b] ? warnings_flag[b] : res;
|
{
|
||||||
if (res == severity_warning && warnings_are_errors)
|
res = res < warnings_flag[b] ? warnings_flag[b] : res;
|
||||||
res = severity_error;
|
/* If the diagnostic is enabled, and -Werror is enabled,
|
||||||
|
and -Wno-error=foo was not explicitly requested, this
|
||||||
|
is an error. */
|
||||||
|
if (res == severity_warning
|
||||||
|
&& (errority_flag[b] == errority_enabled
|
||||||
|
|| (warnings_are_errors
|
||||||
|
&& errority_flag[b] != errority_disabled)))
|
||||||
|
res = severity_error;
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -956,15 +956,9 @@ without_period: "WITHOUT.PERIOD";
|
|||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
|
|
||||||
# POSIX Yacc accept periods, but not dashes.
|
# POSIX Yacc accept periods, but not dashes.
|
||||||
AT_BISON_CHECK([--yacc -Wno-error input.y], [], [],
|
AT_BISON_CHECK([--yacc input.y], [1], [],
|
||||||
[[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
|
[[input.y:9.8-16: error: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Werror=yacc]
|
||||||
input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
|
input.y:20.8-16: error: POSIX Yacc forbids dashes in symbol names: with-dash [-Werror=yacc]
|
||||||
]])
|
|
||||||
|
|
||||||
# So warn about them.
|
|
||||||
AT_BISON_CHECK([-Wyacc input.y], [], [],
|
|
||||||
[[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
|
|
||||||
input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
|
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# Dashes are fine for GNU Bison.
|
# Dashes are fine for GNU Bison.
|
||||||
@@ -1768,11 +1762,11 @@ AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
|
|||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
## --------------------------------------------- ##
|
## ---------------------- ##
|
||||||
## -Werror is not affected by -Wnone and -Wall. ##
|
## -Werror combinations. ##
|
||||||
## --------------------------------------------- ##
|
## ---------------------- ##
|
||||||
|
|
||||||
AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
|
AT_SETUP([[-Werror combinations]])
|
||||||
|
|
||||||
AT_DATA([[input.y]],
|
AT_DATA([[input.y]],
|
||||||
[[%%
|
[[%%
|
||||||
@@ -1798,6 +1792,18 @@ AT_BISON_CHECK([[-Werror,no-all,other input.y]], [[1]], [[]],
|
|||||||
[[input.y:2.15: error: stray '$' [-Werror=other]
|
[[input.y:2.15: error: stray '$' [-Werror=other]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
# Check that -Wno-error keeps warnings enabled, but non fatal.
|
||||||
|
AT_BISON_CHECK([[-Werror -Wno-error=other input.y]], [[0]], [[]],
|
||||||
|
[[input.y:2.15: warning: stray '$' [-Wother]
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_BISON_CHECK([[-Wno-error=other -Werror input.y]], [[0]], [[]],
|
||||||
|
[[input.y:2.15: warning: stray '$' [-Wother]
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_BISON_CHECK([[-Werror=other -Wno-other input.y]], [[0]], [[]],
|
||||||
|
[[]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -635,9 +635,12 @@ m4_define([AT_BISON_CHECK_],
|
|||||||
# ----------------------------------------------------------
|
# ----------------------------------------------------------
|
||||||
# Check that warnings (if some are expected) are correctly
|
# Check that warnings (if some are expected) are correctly
|
||||||
# turned into errors with -Werror, etc.
|
# turned into errors with -Werror, etc.
|
||||||
|
#
|
||||||
|
# When -Wno-error is used, the rules are really different, don't try.
|
||||||
m4_define([AT_BISON_CHECK_WARNINGS],
|
m4_define([AT_BISON_CHECK_WARNINGS],
|
||||||
[m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
|
[m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
|
||||||
[m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
|
m4_bregexp([$1], [-Wno-error=]), [-1],
|
||||||
|
[m4_null_if([$2], [AT_BISON_CHECK_WARNINGS_($@)])])])
|
||||||
|
|
||||||
m4_define([AT_BISON_CHECK_WARNINGS_],
|
m4_define([AT_BISON_CHECK_WARNINGS_],
|
||||||
[[# Defining POSIXLY_CORRECT causes bison to complain if options are
|
[[# Defining POSIXLY_CORRECT causes bison to complain if options are
|
||||||
|
|||||||
Reference in New Issue
Block a user