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.
This commit is contained in:
Akim Demaille
2018-10-22 08:36:01 +02:00
parent 4b0efdeb28
commit 0021bc3e28
2 changed files with 25 additions and 8 deletions

View File

@@ -360,7 +360,7 @@ m4_define([b4_shared_declarations],
void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym);
/// Pop \a n symbols from the stack. /// Pop \a n symbols from the stack.
void yypop_ (unsigned n = 1); void yypop_ (int n = 1);
/// Constants. /// Constants.
enum enum
@@ -689,7 +689,7 @@ m4_if(b4_prefix, [yy], [],
} }
void void
]b4_parser_class_name[::yypop_ (unsigned n) ]b4_parser_class_name[::yypop_ (int n)
{ {
yystack_.pop (n); yystack_.pop (n);
} }

View File

@@ -49,6 +49,15 @@ m4_define([b4_stack_define],
return seq_[size () - 1 - i]; return seq_[size () - 1 - i];
} }
/// Random access.
///
/// Index 0 returns the topmost element.
T&
operator[] (int i)
{
return operator[] (size_type (i));
}
/// Random access. /// Random access.
/// ///
/// Index 0 returns the topmost element. /// Index 0 returns the topmost element.
@@ -58,6 +67,15 @@ m4_define([b4_stack_define],
return seq_[size () - 1 - i]; 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. /// Steal the contents of \a t.
/// ///
/// Close to move-semantics. /// Close to move-semantics.
@@ -69,9 +87,9 @@ m4_define([b4_stack_define],
} }
void void
pop (size_type n = 1) pop (int n = 1)
{ {
for (; n; --n) for (; 0 < n; --n)
seq_.pop_back (); seq_.pop_back ();
} }
@@ -111,21 +129,20 @@ m4_define([b4_stack_define],
class slice class slice
{ {
public: public:
typedef typename S::size_type size_type; slice (const S& stack, int range)
slice (const S& stack, size_type range)
: stack_ (stack) : stack_ (stack)
, range_ (range) , range_ (range)
{} {}
const T& const T&
operator[] (size_type i) const operator[] (int i) const
{ {
return stack_[range_ - i]; return stack_[range_ - i];
} }
private: private:
const S& stack_; const S& stack_;
size_type range_; int range_;
}; };
]]) ]])