** Warnings
-*** Deprecated constructs
+*** Enhancements of the -Werror option
- 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.
+ 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
-*** Warning categories are now displayed
+ 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.
+
*** Useless semantic types
Bison now warns about useless (uninhabited) semantic types. Since
* 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.
@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
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)
static inline void
complains (const location *loc, warnings flags, const char *message,
va_list args)
+
{
- if (flags & complaint)
- {
- error_message (loc, complaint,
- indent_ptr && *indent_ptr ? NULL : _("error"),
- message, args);
- complaint_issued = true;
- }
- else if (flags & fatal)
+ 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);
- }
+ error_message (loc, fatal, _("fatal error"), message, args);
+ exit (EXIT_FAILURE);
}
- 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);
}
}
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;
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;
break;
case 'y':
+ warnings_flag |= Wyacc;
+ errors_flag |= Wyacc;
yacc_flag = true;
break;
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.
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]])