c++: fixes for old compilers

On the CI with GCC 6:

    examples/c++/calc++/parser.cc:845:5: error: 'ptrdiff_t' was not declared in this scope
         ptrdiff_t yycount = 0;
         ^~~~~~~~~
    examples/c++/calc++/parser.cc:845:5: note: suggested alternatives:
    /usr/include/x86_64-linux-gnu/c++/6/bits/c++config.h:202:28: note:   'std::ptrdiff_t'
       typedef __PTRDIFF_TYPE__ ptrdiff_t;
                                ^~~~~~~~~

* data/skeletons/lalr1.cc: Qualify ptrdiff_t and size_t with std::.
This commit is contained in:
Akim Demaille
2019-10-02 22:04:59 +02:00
parent d96fff6115
commit 5df33278b4
2 changed files with 14 additions and 14 deletions

View File

@@ -1155,7 +1155,7 @@ b4_dollar_popdef])[]dnl
#if ]b4_api_PREFIX[DEBUG #if ]b4_api_PREFIX[DEBUG
YYCDEBUG << "LAC: checking lookahead " << yytname_[yytoken] << ':'; YYCDEBUG << "LAC: checking lookahead " << yytname_[yytoken] << ':';
#endif #endif
ptrdiff_t lac_top = 0; std::ptrdiff_t lac_top = 0;
while (true) while (true)
{ {
state_type top_state = (yylac_stack_.empty () state_type top_state = (yylac_stack_.empty ()
@@ -1194,12 +1194,12 @@ b4_dollar_popdef])[]dnl
YYCDEBUG << " R" << yyrule - 1; YYCDEBUG << " R" << yyrule - 1;
// Pop the corresponding number of values from the stack. // Pop the corresponding number of values from the stack.
{ {
ptrdiff_t yylen = yyr2_[yyrule]; std::ptrdiff_t yylen = yyr2_[yyrule];
// First pop from the LAC stack as many tokens as possible. // First pop from the LAC stack as many tokens as possible.
ptrdiff_t lac_size = (ptrdiff_t) yylac_stack_.size (); std::ptrdiff_t lac_size = (std::ptrdiff_t) yylac_stack_.size ();
if (yylen < lac_size) if (yylen < lac_size)
{ {
yylac_stack_.resize ((size_t) (lac_size - yylen)); yylac_stack_.resize ((std::size_t) (lac_size - yylen));
yylen = 0; yylen = 0;
} }
else if (lac_size) else if (lac_size)
@@ -1292,7 +1292,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
{]b4_error_verbose_if([[ {]b4_error_verbose_if([[
// Number of reported tokens (one for the "unexpected", one per // Number of reported tokens (one for the "unexpected", one per
// "expected"). // "expected").
ptrdiff_t yycount = 0; std::ptrdiff_t yycount = 0;
// Its maximum. // Its maximum.
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
// Arguments of yyformat. // Arguments of yyformat.
@@ -1387,7 +1387,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
std::string yyres; std::string yyres;
// Argument number. // Argument number.
ptrdiff_t yyi = 0; std::ptrdiff_t yyi = 0;
for (char const* yyp = yyformat; *yyp; ++yyp) for (char const* yyp = yyformat; *yyp; ++yyp)
if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
{ {

View File

@@ -49,7 +49,7 @@ m4_define([b4_stack_define],
return seq_[size () - 1 - i]; return seq_[size () - 1 - i];
} }
T& T&
operator[] (ptrdiff_t i) operator[] (std::ptrdiff_t i)
{ {
return operator[] (size_type (i)); return operator[] (size_type (i));
} }
@@ -68,7 +68,7 @@ m4_define([b4_stack_define],
return seq_[size () - 1 - i]; return seq_[size () - 1 - i];
} }
const T& const T&
operator[] (ptrdiff_t i) const operator[] (std::ptrdiff_t i) const
{ {
return operator[] (size_type (i)); return operator[] (size_type (i));
} }
@@ -90,7 +90,7 @@ m4_define([b4_stack_define],
/// Pop elements from the stack. /// Pop elements from the stack.
void void
pop (ptrdiff_t n = 1) YY_NOEXCEPT pop (std::ptrdiff_t n = 1) YY_NOEXCEPT
{ {
for (; 0 < n; --n) for (; 0 < n; --n)
seq_.pop_back (); seq_.pop_back ();
@@ -109,10 +109,10 @@ m4_define([b4_stack_define],
{ {
return seq_.size (); return seq_.size ();
} }
ptrdiff_t std::ptrdiff_t
ssize () const YY_NOEXCEPT ssize () const YY_NOEXCEPT
{ {
return (ptrdiff_t) size (); return (std::ptrdiff_t) size ();
} }
/// Iterator on top of the stack (going downwards). /// Iterator on top of the stack (going downwards).
@@ -133,20 +133,20 @@ m4_define([b4_stack_define],
class slice class slice
{ {
public: public:
slice (const stack& stack, ptrdiff_t range) slice (const stack& stack, std::ptrdiff_t range)
: stack_ (stack) : stack_ (stack)
, range_ (range) , range_ (range)
{} {}
const T& const T&
operator[] (ptrdiff_t i) const operator[] (std::ptrdiff_t i) const
{ {
return stack_[range_ - i]; return stack_[range_ - i];
} }
private: private:
const stack& stack_; const stack& stack_;
ptrdiff_t range_; std::ptrdiff_t range_;
}; };
private: private: