diff options
author | Bruno Haible <bruno@clisp.org> | 2016-11-26 01:18:56 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2016-11-26 02:25:50 +0100 |
commit | 658e8264780d2cdd179c54428541ca4954a47b08 (patch) | |
tree | 49ba0501ac8406472dea7e37da3849c73142dc9b | |
parent | bbe4d732f3540e2917d35d5ae49ba42869eebb3b (diff) | |
download | gperf-658e8264780d2cdd179c54428541ca4954a47b08.tar.gz |
Avoid 'warning: use of old-style cast' in output code.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/output.cc | 31 | ||||
-rw-r--r-- | src/output.h | 5 |
3 files changed, 40 insertions, 7 deletions
@@ -1,5 +1,16 @@ 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> + Avoid 'warning: implicit conversion changes signedness' in output code. * src/output.cc (Output::output_lookup_function_body): Emit declaration of 'key' as 'unsigned int', not 'int'. Optimize comparison accordingly. diff --git a/src/output.cc b/src/output.cc index e60f8f7..c42fbba 100644 --- a/src/output.cc +++ b/src/output.cc @@ -749,15 +749,11 @@ void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1, /* ------------------------------------------------------------------------- */ -/* Generates a C expression for an asso_values[] reference. */ +/* Generates a C expression for an asso_values[] index. */ void -Output::output_asso_values_ref (int pos) const +Output::output_asso_values_index (int pos) const { - printf ("asso_values["); - /* Always cast to unsigned char. This is necessary when the alpha_inc - is nonzero, and also avoids a gcc warning "subscript has type 'char'". */ - printf ("(unsigned char)"); if (pos == Positions::LASTCHAR) printf ("str[len - 1]"); else @@ -766,6 +762,29 @@ Output::output_asso_values_ref (int pos) const if (_alpha_inc[pos]) printf ("+%u", _alpha_inc[pos]); } +} + +/* Generates a C expression for an asso_values[] reference. */ + +void +Output::output_asso_values_ref (int pos) const +{ + printf ("asso_values["); + /* Always cast to unsigned char. This is necessary when the alpha_inc + is nonzero, and also avoids a gcc warning "subscript has type 'char'". */ + if (option[CPLUSPLUS]) + { + /* 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 + { + printf ("(unsigned char)"); + output_asso_values_index (pos); + } printf ("]"); } diff --git a/src/output.h b/src/output.h index 6f61a04..397cde6 100644 --- a/src/output.h +++ b/src/output.h @@ -2,7 +2,7 @@ /* 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> and Bruno Haible <bruno@clisp.org>. @@ -71,6 +71,9 @@ private: /* Outputs the maximum and minimum hash values etc. */ 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. */ void output_asso_values_ref (int pos) const; |