diagnostics: revamp the handling of -Werror

Recent discussions with Joel E. Denny
(http://lists.gnu.org/archive/html/bison-patches/2013-02/msg00026.html)
show that it is desirable to tell the difference between an option
that was explicitly disabled with -Wno-foo, as opposed to be left
unset.  The current framework does not allow this.

Instead of having a first int to store which options are enabled, and
another to store which are turned into errors, use an array that for
each warning category tells its status: disabled, unset, warning,
error.

* src/complain.h, src/complain.c (warning_bit): New enum.
(warnings): Use it.
(severity): New enum.
(warnings_flag): Now an array of severity.
(errors_flag): Remove, now done by warnings_flag.
(complain_init): New function, to initialie warnings_flag.
(warnings_are_errors): New Boolean, for -Werror.
* src/complain.c (warning_severity): New.
(warnings_print_categories, complains): Use it.
* src/getargs.c (warning_argmatch): Adjust to use warnings_flag.
(warnings_argmatch): Ditto.
Handle -Werror and -Wno-error here.
(getargs): Adjust.
* src/main.c (main): Call complain_init.
* tests/input.at (Invalid options): Add more corner cases.
This commit is contained in:
Akim Demaille
2013-02-14 09:25:36 +01:00
parent 4a3c55cf1a
commit 808e523db4
5 changed files with 153 additions and 67 deletions

View File

@@ -28,17 +28,32 @@
| --warnings. |
`-------------*/
/** The bits assigned to each warning type. */
typedef enum
{
Wnone = 0, /**< Issue no warnings. */
Wmidrule_values = 1 << 0, /**< Unset or unused midrule values. */
Wyacc = 1 << 1, /**< POSIXME. */
Wconflicts_sr = 1 << 2, /**< S/R conflicts. */
Wconflicts_rr = 1 << 3, /**< R/R conflicts. */
Wdeprecated = 1 << 4, /**< Obsolete constructs. */
Wprecedence = 1 << 5, /**< Useless precedence and associativity. */
warning_midrule_values, /**< Unset or unused midrule values. */
warning_yacc, /**< POSIXME. */
warning_conflicts_sr, /**< S/R conflicts. */
warning_conflicts_rr, /**< R/R conflicts. */
warning_deprecated, /**< Obsolete constructs. */
warning_precedence, /**< Useless precedence and associativity. */
warning_other, /**< All other warnings. */
Wother = 1 << 6, /**< All other warnings. */
warnings_size /**< The number of warnings. Must be last. */
} warning_bit;
typedef enum
{
/**< Issue no warnings. */
Wnone = 0,
Wmidrule_values = 1 << warning_midrule_values,
Wyacc = 1 << warning_yacc,
Wconflicts_sr = 1 << warning_conflicts_sr,
Wconflicts_rr = 1 << warning_conflicts_rr,
Wdeprecated = 1 << warning_deprecated,
Wprecedence = 1 << warning_precedence,
Wother = 1 << warning_other,
Werror = 1 << 10, /** This bit is no longer used. */
@@ -51,11 +66,25 @@ typedef enum
Wall = ~complaint & ~fatal & ~silent
} warnings;
/** What warnings are issued. */
extern warnings warnings_flag;
/** What warnings are made errors. */
extern warnings errors_flag;
/** For each warning type, its severity. */
typedef enum
{
severity_disabled = 0,
severity_unset = 1,
severity_warning = 2,
severity_error = 3,
severity_fatal = 4
} severity;
/** Whether -Werror was set. */
extern bool warnings_are_errors;
/** For each warning type, its severity. */
extern severity warnings_flag[];
/** Initialize this module. */
void complain_init (void);
/** Make a complaint, with maybe a location. */
void complain (location const *loc, warnings flags, char const *message, ...)