1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

Avoid 'warning: use of old-style cast' in output code.

This commit is contained in:
Bruno Haible
2016-11-26 01:18:56 +01:00
parent bbe4d732f3
commit 658e826478
3 changed files with 40 additions and 7 deletions

View File

@@ -1,3 +1,14 @@
2016-11-26 Bruno Haible <bruno@clisp.org>
Avoid 'warning: use of old-style cast' in output code.
* src/output.h (Output::output_asso_values_index): New method
declaration.
* src/output.cc (Output::output_asso_values_index): New method,
extracted from Output::output_asso_values_ref.
(Output::output_asso_values_ref): Use it. In C++ mode, emit C++ style
cast syntax.
Reported at <https://savannah.gnu.org/bugs/?44887>.
2016-11-26 Bruno Haible <bruno@clisp.org> 2016-11-26 Bruno Haible <bruno@clisp.org>
Avoid 'warning: implicit conversion changes signedness' in output code. Avoid 'warning: implicit conversion changes signedness' in output code.

View File

@@ -749,6 +749,21 @@ void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1,
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* Generates a C expression for an asso_values[] index. */
void
Output::output_asso_values_index (int pos) const
{
if (pos == Positions::LASTCHAR)
printf ("str[len - 1]");
else
{
printf ("str[%d]", pos);
if (_alpha_inc[pos])
printf ("+%u", _alpha_inc[pos]);
}
}
/* Generates a C expression for an asso_values[] reference. */ /* Generates a C expression for an asso_values[] reference. */
void void
@@ -757,14 +772,18 @@ Output::output_asso_values_ref (int pos) const
printf ("asso_values["); printf ("asso_values[");
/* Always cast to unsigned char. This is necessary when the alpha_inc /* Always cast to unsigned char. This is necessary when the alpha_inc
is nonzero, and also avoids a gcc warning "subscript has type 'char'". */ is nonzero, and also avoids a gcc warning "subscript has type 'char'". */
printf ("(unsigned char)"); if (option[CPLUSPLUS])
if (pos == Positions::LASTCHAR) {
printf ("str[len - 1]"); /* In C++, a C style cast may lead to a 'warning: use of old-style cast'.
Therefore prefer the C++ style cast syntax. */
printf ("static_cast<unsigned char>(");
output_asso_values_index (pos);
printf (")");
}
else else
{ {
printf ("str[%d]", pos); printf ("(unsigned char)");
if (_alpha_inc[pos]) output_asso_values_index (pos);
printf ("+%u", _alpha_inc[pos]);
} }
printf ("]"); printf ("]");
} }

View File

@@ -2,7 +2,7 @@
/* Output routines. /* Output routines.
Copyright (C) 1989-1998, 2000, 2002-2003, 2009 Free Software Foundation, Inc. Copyright (C) 1989-1998, 2000, 2002-2003, 2009, 2016 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu> Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>. and Bruno Haible <bruno@clisp.org>.
@@ -71,6 +71,9 @@ private:
/* Outputs the maximum and minimum hash values etc. */ /* Outputs the maximum and minimum hash values etc. */
void output_constants (struct Output_Constants&) const; void output_constants (struct Output_Constants&) const;
/* Generates a C expression for an asso_values[] index. */
void output_asso_values_index (int pos) const;
/* Generates a C expression for an asso_values[] reference. */ /* Generates a C expression for an asso_values[] reference. */
void output_asso_values_ref (int pos) const; void output_asso_values_ref (int pos) const;