mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
warnings: fix early exit of warnings treated as errors
Treating warnings as errors caused Bison to exit earlier than needed, making it hide warnings that would have been printed had -Werror not been set. Also, fix a bug that caused some context information of errors to not be shown. * src/complain.c (complaint_issued): Rename as... (complaint_status): This, and change its type from boolean to * src/complain.h (err_status): This, new enumeration. * src/main.c (main): Adjust (only finish early if an actual complaint was risen, not a mere warning treated an error). * src/reader.c: Adjust.
This commit is contained in:
@@ -34,7 +34,7 @@ warnings warnings_flag =
|
|||||||
|
|
||||||
warnings errors_flag;
|
warnings errors_flag;
|
||||||
|
|
||||||
bool complaint_issued;
|
err_status complaint_status = status_none;
|
||||||
static unsigned *indent_ptr = 0;
|
static unsigned *indent_ptr = 0;
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -129,8 +129,11 @@ complains (const location *loc, warnings flags, const char *message,
|
|||||||
: flags & (errors_flag | complaint) ? _("error")
|
: flags & (errors_flag | complaint) ? _("error")
|
||||||
: _("warning");
|
: _("warning");
|
||||||
|
|
||||||
complaint_issued |= flags & (complaint | errors_flag);
|
if ((flags & complaint) && complaint_status < status_complaint)
|
||||||
if (flags & (warnings_flag | silent | fatal | complaint))
|
complaint_status = status_complaint;
|
||||||
|
else if ((flags & (warnings_flag & errors_flag)) && ! complaint_status)
|
||||||
|
complaint_status = status_warning_as_error;
|
||||||
|
if (flags & (warnings_flag | fatal | complaint))
|
||||||
error_message (loc, flags, prefix, message, args);
|
error_message (loc, flags, prefix, message, args);
|
||||||
if (flags & fatal)
|
if (flags & fatal)
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
|
|||||||
@@ -70,7 +70,18 @@ void complain_indent (location const *loc, warnings flags, unsigned *indent,
|
|||||||
char const *message, ...)
|
char const *message, ...)
|
||||||
__attribute__ ((__format__ (__printf__, 4, 5)));
|
__attribute__ ((__format__ (__printf__, 4, 5)));
|
||||||
|
|
||||||
|
|
||||||
|
/** Warnings treated as errors shouldn't stop the execution as regular errors
|
||||||
|
should (because due to their nature, it is safe to go on). Thus, there are
|
||||||
|
three possible execution statuses. */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
status_none,
|
||||||
|
status_warning_as_error,
|
||||||
|
status_complaint
|
||||||
|
} err_status;
|
||||||
|
|
||||||
/** Whether an error was reported. */
|
/** Whether an error was reported. */
|
||||||
extern bool complaint_issued;
|
extern err_status complaint_status;
|
||||||
|
|
||||||
#endif /* !COMPLAIN_H_ */
|
#endif /* !COMPLAIN_H_ */
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ main (int argc, char *argv[])
|
|||||||
reader ();
|
reader ();
|
||||||
timevar_pop (TV_READER);
|
timevar_pop (TV_READER);
|
||||||
|
|
||||||
if (complaint_issued)
|
if (complaint_status == status_complaint)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
/* Find useless nonterminals and productions and reduce the grammar. */
|
/* Find useless nonterminals and productions and reduce the grammar. */
|
||||||
@@ -173,7 +173,7 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
/* Stop if there were errors, to avoid trashing previous output
|
/* Stop if there were errors, to avoid trashing previous output
|
||||||
files. */
|
files. */
|
||||||
if (complaint_issued)
|
if (complaint_status == status_complaint)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
/* Lookahead tokens are no longer needed. */
|
/* Lookahead tokens are no longer needed. */
|
||||||
@@ -215,5 +215,5 @@ main (int argc, char *argv[])
|
|||||||
timevar_stop (TV_TOTAL);
|
timevar_stop (TV_TOTAL);
|
||||||
timevar_print (stderr);
|
timevar_print (stderr);
|
||||||
|
|
||||||
return complaint_issued ? EXIT_FAILURE : EXIT_SUCCESS;
|
return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ reader (void)
|
|||||||
gram_parse ();
|
gram_parse ();
|
||||||
prepare_percent_define_front_end_variables ();
|
prepare_percent_define_front_end_variables ();
|
||||||
|
|
||||||
if (! complaint_issued)
|
if (complaint_status < status_complaint)
|
||||||
check_and_convert_grammar ();
|
check_and_convert_grammar ();
|
||||||
|
|
||||||
xfclose (gram_in);
|
xfclose (gram_in);
|
||||||
|
|||||||
Reference in New Issue
Block a user