errors: change output, and improve -y coherence

The prefix of warnings treated as errors is now "error: ". Also, their
suffix now reflects the changes in the Werror option format.

An output for -Werror=other used to be:
  bison: warnings being treated as errors
  input.y:1.1: warning: stray ',' treated as white space [-Wother]

It is now:
  bison: warnings being treated as errors
  input.y:1.1: error: stray ',' treated as white space [-Werror=other]

The line "warnings being treated as errors" no longer adds any info,
it will be removed in a forthcoming change.

* NEWS: Add entry "Enhancement of the -Werror"
* doc/bison.texi: Move the warnings-as-error to a new bullet.
* src/complain.c (complains): Refactor, change the prefix of warnings
that are treated as errors.
(warnings_print_categories): Support for [-Werror=CATEGORY] display
* src/getargc.c (getargs): -y implies -Werror=yacc
* tests/input.at: Update expected --yacc output for coherence.

Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
This commit is contained in:
Akim Demaille
2012-09-27 12:19:09 +02:00
parent 9503b0a4a8
commit 1048a1c901
6 changed files with 100 additions and 41 deletions

53
NEWS
View File

@@ -13,18 +13,59 @@ GNU Bison NEWS
** Warnings
*** Enhancements of the -Werror option
The -Werror=CATEGORY option is now recognized, and will treat specified
warnings as errors. The warnings need not have been explictly activated
using the -W option, this is similar to what gcc 4.7 does.
For example, given the following command line, Bison will treat both
warnings related to POSIX Yacc incompatiblities and S/R conflicts as
errors (and only those):
$ bison -Werror=yacc,error=conflicts-sr input.y
If no categories are specified, -Werror will make all active warnings into
errors. For example, the following line does the same the previous example:
$ bison -Werror -Wnone -Wyacc -Wconflicts-sr input.y
(By default -Wconflicts-sr,conflicts-rr,deprecated,other is enabled.)
Note that the categories in this -Werror option may not be prefixed with
"no-". However, -Wno-error[=CATEGORY] is valid.
Note that -y enables -Werror=yacc. Therefore it is now possible to require
Yacc-like behavior (e.g., always generate y.tab.c), but to report
incompatibilities as warnings: "-y -Wno-error=yacc".
*** Warning categories are now displayed and prefix changes
For instance:
foo.y:4.6: warning: type clash on default action: <foo> != <bar> [-Wother]
In the case of warnings treated as errors, the suffix is displayed, in a
manner similar to gcc, as [-Werror=CATEGORY]. Also, the prefix is changed
from "warning: " to "error: ".
For instance, considering the above change, an output for -Werror=other
would have been:
bison: warnings being treated as errors
input.y:1.1: warning: stray ',' treated as white space [-Wother]
But it is actually:
bison: warnings being treated as errors
input.y:1.1: error: stray ',' treated as white space [-Werror=other]
*** Deprecated constructs
The new 'deprecated' warning category flags obsolete constructs whose
support will be discontinued. It is enabled by default. These warnings
used to be reported as 'other' warnings.
*** Warning categories are now displayed
For instance:
foo.y:4.6: warning: type clash on default action: <foo> != <bar> [-Wother]
*** Useless semantic types
Bison now warns about useless (uninhabited) semantic types. Since

5
TODO
View File

@@ -1,4 +1,9 @@
* Short term
** erroneous test
src/complains.c changed the output of errors (prefixes), but the m4 macros
have not been changed to reflect this change.
Fix the message "an identifier expected" (m4) in tests/input.at.
** push-parser
Check it too when checking the different kinds of parsers. And be
sure to check that the initial-action is performed once per parsing.

View File

@@ -9263,12 +9263,33 @@ All the warnings.
@item none
Turn off all the warnings.
@item error
Treat warnings as errors.
See @option{-Werror}, below.
@end table
A category can be turned off by prefixing its name with @samp{no-}. For
instance, @option{-Wno-yacc} will hide the warnings about
POSIX Yacc incompatibilities.
@item -Werror[=@var{category}]
@itemx -Wno-error[=@var{category}]
Enable warnings falling in @var{category}, and treat them as errors. If no
@var{category} is given, it defaults to making all enabled warnings into errors.
@var{category} is the same as for @option{--warnings}, with the exception that
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
the following commands are @emph{not} equivalent, as the first will not treat
S/R conflicts as errors.
@example
$ bison -Werror=yacc,conflicts-sr input.y
$ bison -Werror=yacc,error=conflicts-sr input.y
@end example
@end table
@noindent

View File

@@ -57,7 +57,9 @@ warnings_print_categories (warnings warn_flags)
for (i = 0; i < ARRAY_CARDINALITY (warn_names); ++i)
if (warn_flags & 1 << i)
{
fprintf (stderr, "%s-W%s", any ? ", " : " [", warn_names[i]);
bool err = warn_flags & errors_flag;
fprintf (stderr, "%s-W", any ? ", " : " [");
fprintf (stderr, "%s%s", err ? "error=" : "" , warn_names[i]);
any = true;
}
if (any)
@@ -121,39 +123,22 @@ error_message (const location *loc, warnings flags, const char *prefix,
static inline void
complains (const location *loc, warnings flags, const char *message,
va_list args)
{
if (flags & complaint)
if (flags & fatal)
{
error_message (loc, complaint,
indent_ptr && *indent_ptr ? NULL : _("error"),
message, args);
complaint_issued = true;
error_message (loc, fatal, _("fatal error"), message, args);
exit (EXIT_FAILURE);
}
else if (flags & fatal)
{
error_message (loc, fatal, _("fatal error"), message, args);
exit (EXIT_FAILURE);
}
else if (flags & Wyacc)
{
if (yacc_flag)
{
error_message (loc, flags, NULL, message, args);
complaint_issued = true;
}
else if (warnings_flag & Wyacc)
{
set_warning_issued (Wyacc);
error_message (loc, flags,
indent_ptr && *indent_ptr ? NULL : _("warning"),
message, args);
}
}
else if (warnings_flag & flags)
else if (flags & (complaint | warnings_flag))
{
const char* prefix =
flags & (errors_flag | complaint) ? _("error") : _("warning");
if (flags & complaint)
complaint_issued = true;
set_warning_issued (flags);
error_message (loc, flags,
indent_ptr && *indent_ptr ? NULL : _("warning"),
indent_ptr && *indent_ptr ? NULL : prefix,
message, args);
}
}

View File

@@ -87,7 +87,7 @@ flags_argmatch (const char *option,
args = strtok (args, ",");
while (args)
{
int value = all;
int value = 0;
int *save_flags = flags;
int no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
int err = STRPREFIX_LIT ("error", args + no) ? 5 : 0;
@@ -99,7 +99,12 @@ flags_argmatch (const char *option,
if (!value)
{
if (no)
/* With a simpler 'if (no)' version, -Werror means -Werror=all
(or rather, -Werror=no-none, but that syntax is invalid).
The difference is:
- Werror activates all errors, but not the warnings
- Werror=all activates errors, and all warnings */
if (no ? !err : err)
*flags |= all;
else
*flags &= ~all;
@@ -681,6 +686,8 @@ getargs (int argc, char *argv[])
break;
case 'y':
warnings_flag |= Wyacc;
errors_flag |= Wyacc;
yacc_flag = true;
break;

View File

@@ -751,9 +751,9 @@ without_period: "WITHOUT.PERIOD";
AT_BISON_OPTION_POPDEFS
# POSIX Yacc accept periods, but not dashes.
AT_BISON_CHECK([--yacc input.y], [1], [],
[[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
AT_BISON_CHECK([--yacc -Wno-error input.y], [], [],
[[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
]])
# So warn about them.
@@ -1461,7 +1461,7 @@ AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
[[bison: warnings being treated as errors
input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar [-Wyacc]
input.y:2.1-7: error: POSIX Yacc forbids dashes in symbol names: foo-bar [-Werror=yacc]
]])
[mv stderr experr]
AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])