bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] errors: change output, and improve -y coherence


From: Theophile Ranquet
Subject: [PATCH 2/3] errors: change output, and improve -y coherence
Date: Thu, 27 Sep 2012 10:52:46 +0000

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.
---
 NEWS           | 43 ++++++++++++++++++++++++++++++++++++++++++-
 TODO           |  5 +++++
 doc/bison.texi | 24 +++++++++++++++++++++++-
 src/complain.c | 41 +++++++++++++----------------------------
 src/getargs.c  | 11 +++++++++--
 tests/input.at |  8 ++++----
 6 files changed, 96 insertions(+), 36 deletions(-)

diff --git a/NEWS b/NEWS
index 7e5bda2..757c489 100644
--- a/NEWS
+++ b/NEWS
@@ -13,18 +13,59 @@ GNU Bison NEWS
 
 ** Warnings
 
+-*** Enhancements of the -Werror
+
+  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".
+
 *** 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
+*** 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]
+
 *** Useless semantic types
 
   Bison now warns about useless (uninhabited) semantic types.  Since
diff --git a/TODO b/TODO
index 051ca7c..cce754b 100644
--- a/TODO
+++ b/TODO
@@ -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.
diff --git a/doc/bison.texi b/doc/bison.texi
index 1297a36..60dc25f 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -9263,12 +9263,34 @@ 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.
+
address@hidden address@hidden
address@hidden address@hidden
+Enable warnings falling in @var{category}, and treat them as errors.  If no
address@hidden is given, it defaults to making all enabled warnings into errors.
+
address@hidden 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
address@hidden However, the warning itself won't be disabled, or enabled, by
+this option.
+
+Note that the precedence of the '=' and ',' operators is such that the
+following commands are *not* equivalent, as the first will not treat S/R
+conflicts as errors.
+
address@hidden
+$ bison -Werror=yacc,conflicts-sr input.y
+$ bison -Werror=yacc,error=conflicts-sr input.y
address@hidden example
+
 @end table
 
 @noindent
diff --git a/src/complain.c b/src/complain.c
index 849a71c..d4098f7 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -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)
-    {
-      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);
     }
 }
diff --git a/src/getargs.c b/src/getargs.c
index 90b2655..695ad12 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -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;
 
diff --git a/tests/input.at b/tests/input.at
index 5bb707e..c149894 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -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]])
-- 
1.7.11.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]