From 4631c34fb78bebfd3764ebe77d4f4baae757dbf6 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Sun, 1 Aug 2010 18:51:46 -0400 Subject: -Werror: fix for rules useless in parser after conflicts. * NEWS (2.4.3): Document fix. * src/complain.c (error_message): Extend to handle incomplete error messages so warn and warn_at can be used in more cases. * src/gram.c (grammar_rules_useless_report): Use warn_at so that -Werror is always obeyed. * src/reduce.c (reduce_print): Use warn so that the "warnings being treated as errors" message is printed consistently before the first warning message. This makes testing easier. * tests/local.at (AT_BISON_WERROR_MSG): New macro. (AT_BISON_CHECK_NO_XML): Extend to check -Werror and --warnings=error when warnings appear in bison's stderr. (cherry picked from commit 954474bfa1a875eeefe9aa1989d9c7be6f64726b) --- src/complain.c | 14 +++++++++++--- src/gram.c | 9 +++++---- src/reduce.c | 24 ++++++++---------------- 3 files changed, 24 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/complain.c b/src/complain.c index d5d17b7c..22ad4248 100644 --- a/src/complain.c +++ b/src/complain.c @@ -38,7 +38,10 @@ static unsigned *indent_ptr = 0; * \param loc the location, defaulting to the current file, * or the program name. * \param prefix put before the message (e.g., "warning"). - * \param message the error message, a printf format string. + * \param message the error message, a printf format string. Iff it + * ends with ": ", then no trailing newline is printed, + * and the caller should print the remaining + * newline-terminated message to stderr. * \param args the arguments of the format string. */ static @@ -68,8 +71,13 @@ error_message (location *loc, fprintf (stderr, "%s: ", prefix); vfprintf (stderr, message, args); - putc ('\n', stderr); - fflush (stderr); + { + size_t l = strlen (message); + if (l < 2 || message[l-2] != ':' || message[l-1] != ' ') { + putc ('\n', stderr); + fflush (stderr); + } + } } /** Wrap error_message() with varargs handling. */ diff --git a/src/gram.c b/src/gram.c index 10a1953a..74ead640 100644 --- a/src/gram.c +++ b/src/gram.c @@ -23,11 +23,12 @@ #include +#include "complain.h" #include "gram.h" +#include "print-xml.h" #include "reader.h" #include "reduce.h" #include "symtab.h" -#include "print-xml.h" /* Comments for these variables are in gram.h. */ @@ -308,9 +309,9 @@ grammar_rules_useless_report (const char *message) for (r = 0; r < nrules ; ++r) if (!rules[r].useful) { - location_print (stderr, rules[r].location); - fprintf (stderr, ": %s: %s: ", _("warning"), message); - rule_print (&rules[r], stderr); + warn_at (rules[r].location, "%s: ", message); + rule_print (&rules[r], stderr); + fflush (stderr); } } diff --git a/src/reduce.c b/src/reduce.c index 4cec048e..6e16ce31 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -383,23 +383,15 @@ static void reduce_print (void) { if (nuseless_nonterminals > 0) - { - fprintf (stderr, "%s: %s: ", grammar_file, _("warning")); - fprintf (stderr, ngettext ("%d nonterminal useless in grammar", - "%d nonterminals useless in grammar", - nuseless_nonterminals), - nuseless_nonterminals); - fprintf (stderr, "\n"); - } + warn (ngettext ("%d nonterminal useless in grammar", + "%d nonterminals useless in grammar", + nuseless_nonterminals), + nuseless_nonterminals); if (nuseless_productions > 0) - { - fprintf (stderr, "%s: %s: ", grammar_file, _("warning")); - fprintf (stderr, ngettext ("%d rule useless in grammar", - "%d rules useless in grammar", - nuseless_productions), - nuseless_productions); - fprintf (stderr, "\n"); - } + warn (ngettext ("%d rule useless in grammar", + "%d rules useless in grammar", + nuseless_productions), + nuseless_productions); } void -- cgit v1.2.1