]> git.saurik.com Git - bison.git/commitdiff
tests: enable -Wsign-compare and fix corresponding warnings
authorAkim Demaille <akim@lrde.epita.fr>
Fri, 19 Apr 2013 15:13:07 +0000 (17:13 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Fri, 19 Apr 2013 15:13:07 +0000 (17:13 +0200)
-Wsign-compare was disabled for bison's own code, following gnulib's
approach.  However, the generated parsers should not trigger such
warnings.

Reported by Efi Fogel.
http://lists.gnu.org/archive/html/help-bison/2013-04/msg00018.html

See also http://stackoverflow.com/questions/16101062 for the weird
"-(unsigned)i" piece of code.

* configure.ac (warn_tests): Enable -Wsign-compare.
* data/location.cc (position::add_): New.
(position::lines, position::columns): Use it.
* tests/actions.at (AT_CHECK_PRINTER_AND_DESTRUCTOR): Fix signedness issues.

THANKS
configure.ac
data/location.cc
tests/actions.at

diff --git a/THANKS b/THANKS
index 320e26f1743eef391600b9023020f78f1d0e886c..e2cf97a615b8516e40fc598361081a9d1990958d 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -38,6 +38,7 @@ Derek M. Jones            derek@knosof.co.uk
 Di-an Jan                 dianj@freeshell.org
 Dick Streefland           dick.streefland@altium.nl
 Didier Godefroy           dg@ulysium.net
 Di-an Jan                 dianj@freeshell.org
 Dick Streefland           dick.streefland@altium.nl
 Didier Godefroy           dg@ulysium.net
+Efi Fogel                 efifogel@gmail.com
 Enrico Scholz             enrico.scholz@informatik.tu-chemnitz.de
 Eric Blake                ebb9@byu.net
 Evgeny Stambulchik        fnevgeny@plasma-gate.weizmann.ac.il
 Enrico Scholz             enrico.scholz@informatik.tu-chemnitz.de
 Eric Blake                ebb9@byu.net
 Evgeny Stambulchik        fnevgeny@plasma-gate.weizmann.ac.il
index e6ef8baf91a3877b0e255816fc3a76f2a42d9228..df5670cd5d7167b4f6762c270e1577550028671f 100644 (file)
@@ -91,7 +91,7 @@ if test "$enable_gcc_warnings" = yes; then
   # -fno-color-diagnostics: Clang's use of colors in the error
   # messages is confusing the tests looking at the compiler's output
   # (e.g., synclines.at).
   # -fno-color-diagnostics: Clang's use of colors in the error
   # messages is confusing the tests looking at the compiler's output
   # (e.g., synclines.at).
-  warn_tests='-Wundef -pedantic -fno-color-diagnostics'
+  warn_tests='-Wundef -pedantic -Wsign-compare -fno-color-diagnostics'
 
   AC_LANG_PUSH([C])
   # Clang supports many of GCC's -W options, but only issues warnings
 
   AC_LANG_PUSH([C])
   # Clang supports many of GCC's -W options, but only issues warnings
index 309b9c0f7432098d2624393908e756adf189aa34..9a60f2503fee878cea309f691ef216f4f39ee014 100644 (file)
@@ -55,20 +55,14 @@ m4_define([b4_position_define],
       if (count)
         {
           column = ]b4_location_initial_column[u;
       if (count)
         {
           column = ]b4_location_initial_column[u;
-          line =
-            0 < count || -count < line
-            ? line + count
-            : ]b4_location_initial_line[;
+          line = add_ (line, count, ]b4_location_initial_line[);
         }
     }
 
     /// (column related) Advance to the COUNT next columns.
     void columns (int count = 1)
     {
         }
     }
 
     /// (column related) Advance to the COUNT next columns.
     void columns (int count = 1)
     {
-      column =
-        0 < count || -count < column
-        ? column + count
-        : ]b4_location_initial_column[;
+      column = add_ (column, count, ]b4_location_initial_column[);
     }
     /** \} */
 
     }
     /** \} */
 
@@ -78,6 +72,15 @@ m4_define([b4_position_define],
     unsigned int line;
     /// Current column number.
     unsigned int column;
     unsigned int line;
     /// Current column number.
     unsigned int column;
+
+  private:
+    /// Compute max(min, lhs+rhs) (provided min <= lhs).
+    static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
+    {
+      return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
+              ? rhs + lhs
+              : min);
+    }
   };
 
   /// Add and assign a position.
   };
 
   /// Add and assign a position.
index 88aad2584c3843bfc7e0d5e0db09a6fcc3b7a6df..6c1ecbc1f6dfcf65f32e6c11598ebcd299a6d27b 100644 (file)
@@ -605,11 +605,11 @@ static
 {
   static unsigned int counter = 0;
 
 {
   static unsigned int counter = 0;
 
-  int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
+  unsigned int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
   /* As in BASIC, line numbers go from 10 to 10.  */
   ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
   ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
   /* As in BASIC, line numbers go from 10 to 10.  */
   ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
   ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
-  assert (0 <= c && c <= strlen (source));
+  assert (c <= strlen (source));
   if (source[c])
     fprintf (stderr, "sending: '%c'", source[c]);
   else
   if (source[c])
     fprintf (stderr, "sending: '%c'", source[c]);
   else
@@ -848,13 +848,13 @@ AT_CLEANUP
 
 
 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
 
 
 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
-AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
+AT_CHECK_PRINTER_AND_DESTRUCTOR([], [ with union])
 
 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
 
 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
-AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union])
+AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [ with union])
 
 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
 
 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
-AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
+AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [ with union])