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

Avoid "-Wzero-as-null-pointer-constant" warnings on the generated code.

Reported in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-11/msg00123.html>.

* src/output.cc (Output::output_lookup_function_body): To denote a null
pointer, emit a cast expression instead of plain "0".
* tests/c-parse.exp, tests/charsets.exp, tests/chill.exp,
tests/cplusplus.exp, tests/gpc.exp, tests/incomplete.exp,
tests/java.exp, tests/languages.exp, tests/modula2.exp, tests/objc.exp,
tests/permut2.exp, tests/permut3.exp, tests/permutc2.exp,
tests/test-4.exp: Update.
This commit is contained in:
Bruno Haible
2024-11-16 08:22:30 +01:00
parent 8ffda68bfc
commit 2dd5061f4d
16 changed files with 48 additions and 20 deletions

View File

@@ -1,3 +1,16 @@
2024-11-16 Bruno Haible <bruno@clisp.org>
Avoid "-Wzero-as-null-pointer-constant" warnings on the generated code.
Reported in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-11/msg00123.html>.
* src/output.cc (Output::output_lookup_function_body): To denote a null
pointer, emit a cast expression instead of plain "0".
* tests/c-parse.exp, tests/charsets.exp, tests/chill.exp,
tests/cplusplus.exp, tests/gpc.exp, tests/incomplete.exp,
tests/java.exp, tests/languages.exp, tests/modula2.exp, tests/objc.exp,
tests/permut2.exp, tests/permut3.exp, tests/permutc2.exp,
tests/test-4.exp: Update.
2024-10-28 Bruno Haible <bruno@clisp.org>
doc: Improve text rendering in PDF output.

View File

@@ -1,5 +1,5 @@
/* Output routines.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007, 2009, 2011-2012, 2016, 2018, 2021, 2023 Free Software Foundation, Inc.
Copyright (C) 1989-2024 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -1707,6 +1707,17 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash
void
Output::output_lookup_function_body (const Output_Compare& comparison) const
{
/* An expression equivalent to NULL, of type _return_type.
We don't use plain "0", because that would trigger a gcc 15 warning
if the warning option -Wzero-as-null-pointer-constant is in use.
In C++, using "nullptr" if __cplusplus >= 201103L would be possible,
but is not worth the trouble. */
char *null_expression = new char[17 + strlen (_return_type) + 1];
if (option[CPLUSPLUS])
sprintf (null_expression, "static_cast<%s> (0)", _return_type);
else
sprintf (null_expression, "(%s) 0", _return_type);
printf (" if (len <= %sMAX_WORD_LENGTH && len >= %sMIN_WORD_LENGTH)\n"
" {\n"
" %sunsigned int key = %s (str, len);\n\n",
@@ -1755,7 +1766,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
output_switches (_head, num_switches, switch_size, _min_hash_value, _max_hash_value, 10);
printf (" return 0;\n");
printf (" return %s;\n",
null_expression);
if (option[DUP] && _total_duplicates > 0)
{
int indent = 8;
@@ -1798,8 +1810,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
indent, "");
printf ("%*s wordptr++;\n"
"%*s }\n"
"%*s return 0;\n",
indent, "", indent, "", indent, "");
"%*s return %s;\n",
indent, "", indent, "", indent, "", null_expression);
}
printf (" compare:\n");
if (option[TYPE])
@@ -2020,7 +2032,10 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
}
}
printf (" }\n"
" return 0;\n");
" return %s;\n",
null_expression);
delete[] null_expression;
}
/* Generates C code for the lookup function. */

View File

@@ -219,5 +219,5 @@ is_reserved_word (str, len)
return &wordlist[key];
}
}
return 0;
return (struct resword *) 0;
}

View File

@@ -1878,6 +1878,6 @@ in_word_set (register const char *str, register size_t len)
return &wordlist[key];
}
}
return 0;
return (struct charset *) 0;
}

View File

@@ -1550,7 +1550,7 @@ in_word_set (str, len)
resword = &wordlist[299];
goto compare;
}
return 0;
return (struct resword *) 0;
compare:
{
register const char *s = resword->name;
@@ -1560,5 +1560,5 @@ in_word_set (str, len)
}
}
}
return 0;
return (struct resword *) 0;
}

View File

@@ -269,5 +269,5 @@ is_reserved_word (str, len)
return &wordlist[key];
}
}
return 0;
return (struct resword *) 0;
}

View File

@@ -153,5 +153,5 @@ is_reserved_word (register const char *str, register size_t len)
return &wordlist[key];
}
}
return 0;
return (struct resword *) 0;
}

View File

@@ -121,5 +121,5 @@ in_word_set (register const char *str, register size_t len)
return &wordlist[key];
}
}
return 0;
return (struct month *) 0;
}

View File

@@ -199,5 +199,5 @@ java_keyword (str, len)
return &wordlist[key];
}
}
return 0;
return (struct java_keyword *) 0;
}

View File

@@ -1495,7 +1495,7 @@ in_word_set (register const char *str, register size_t len)
return &wordlist[key];
}
}
return 0;
return (struct language *) 0;
}

View File

@@ -246,5 +246,5 @@ in_word_set (register const char *str, register size_t len)
return s;
}
}
return 0;
return (const char *) 0;
}

View File

@@ -194,5 +194,5 @@ is_reserved_word (register const char *str, register size_t len)
return &wordlist[key];
}
}
return 0;
return (struct resword *) 0;
}

View File

@@ -104,5 +104,5 @@ in_word_set (register const char *str, register size_t len)
return s;
}
}
return 0;
return (const char *) 0;
}

View File

@@ -104,5 +104,5 @@ in_word_set (register const char *str, register size_t len)
return s;
}
}
return 0;
return (const char *) 0;
}

View File

@@ -153,5 +153,5 @@ in_word_set (register const char *str, register size_t len)
return s;
}
}
return 0;
return (const char *) 0;
}

View File

@@ -230,5 +230,5 @@ in_word_set (register const char *str, register size_t len)
}
}
}
return 0;
return (struct resword *) 0;
}