bison-patches
[Top][All Lists]
Advanced

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

c++: fix signedness issues


From: Akim Demaille
Subject: c++: fix signedness issues
Date: Mon, 22 Oct 2018 08:41:55 +0200

commit 0021bc3e28edcf1666bacc2c4eb9a0b30232856c
Author: Akim Demaille <address@hidden>
Date:   Mon Oct 22 08:36:01 2018 +0200

    c++: fix signedness issues
    
    * data/lalr1.cc, data/stack.hh: The callers of stack use int, while
    stack is based on size_type.  Add overloads to avoid warnings.

diff --git a/data/lalr1.cc b/data/lalr1.cc
index 0f470994..984be33a 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -360,7 +360,7 @@ m4_define([b4_shared_declarations],
     void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym);
 
     /// Pop \a n symbols from the stack.
-    void yypop_ (unsigned n = 1);
+    void yypop_ (int n = 1);
 
     /// Constants.
     enum
@@ -689,7 +689,7 @@ m4_if(b4_prefix, [yy], [],
   }
 
   void
-  ]b4_parser_class_name[::yypop_ (unsigned n)
+  ]b4_parser_class_name[::yypop_ (int n)
   {
     yystack_.pop (n);
   }
diff --git a/data/stack.hh b/data/stack.hh
index 4f712159..0f1b502e 100644
--- a/data/stack.hh
+++ b/data/stack.hh
@@ -49,6 +49,15 @@ m4_define([b4_stack_define],
       return seq_[size () - 1 - i];
     }
 
+    /// Random access.
+    ///
+    /// Index 0 returns the topmost element.
+    T&
+    operator[] (int i)
+    {
+      return operator[] (size_type (i));
+    }
+
     /// Random access.
     ///
     /// Index 0 returns the topmost element.
@@ -58,6 +67,15 @@ m4_define([b4_stack_define],
       return seq_[size () - 1 - i];
     }
 
+    /// Random access.
+    ///
+    /// Index 0 returns the topmost element.
+    const T&
+    operator[] (int i) const
+    {
+      return operator[] (size_type (i));
+    }
+
     /// Steal the contents of \a t.
     ///
     /// Close to move-semantics.
@@ -69,9 +87,9 @@ m4_define([b4_stack_define],
     }
 
     void
-    pop (size_type n = 1)
+    pop (int n = 1)
     {
-      for (; n; --n)
+      for (; 0 < n; --n)
         seq_.pop_back ();
     }
 
@@ -111,21 +129,20 @@ m4_define([b4_stack_define],
   class slice
   {
   public:
-    typedef typename S::size_type size_type;
-    slice (const S& stack, size_type range)
+    slice (const S& stack, int range)
       : stack_ (stack)
       , range_ (range)
     {}
 
     const T&
-    operator[] (size_type i) const
+    operator[] (int i) const
     {
       return stack_[range_ - i];
     }
 
   private:
     const S& stack_;
-    size_type range_;
+    int range_;
   };
 ]])
 




reply via email to

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