summaryrefslogtreecommitdiff
path: root/src/output.cc
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2016-11-26 01:18:56 +0100
committerBruno Haible <bruno@clisp.org>2016-11-26 02:25:50 +0100
commit658e8264780d2cdd179c54428541ca4954a47b08 (patch)
tree49ba0501ac8406472dea7e37da3849c73142dc9b /src/output.cc
parentbbe4d732f3540e2917d35d5ae49ba42869eebb3b (diff)
downloadgperf-658e8264780d2cdd179c54428541ca4954a47b08.tar.gz
Avoid 'warning: use of old-style cast' in output code.
Diffstat (limited to 'src/output.cc')
-rw-r--r--src/output.cc31
1 files changed, 25 insertions, 6 deletions
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 ("]");
}