diff --git a/ChangeLog b/ChangeLog index f7e8f86..90edd83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2024-11-16 Bruno Haible + + Avoid "-Wzero-as-null-pointer-constant" warnings on the generated code. + Reported in + . + * 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 doc: Improve text rendering in PDF output. diff --git a/src/output.cc b/src/output.cc index e103c74..4309735 100644 --- a/src/output.cc +++ b/src/output.cc @@ -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 and Bruno Haible . @@ -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. */ diff --git a/tests/c-parse.exp b/tests/c-parse.exp index f577abd..2c12ea7 100644 --- a/tests/c-parse.exp +++ b/tests/c-parse.exp @@ -219,5 +219,5 @@ is_reserved_word (str, len) return &wordlist[key]; } } - return 0; + return (struct resword *) 0; } diff --git a/tests/charsets.exp b/tests/charsets.exp index 6bd759e..fb0539d 100644 --- a/tests/charsets.exp +++ b/tests/charsets.exp @@ -1878,6 +1878,6 @@ in_word_set (register const char *str, register size_t len) return &wordlist[key]; } } - return 0; + return (struct charset *) 0; } diff --git a/tests/chill.exp b/tests/chill.exp index 80b1abb..ddffa2f 100644 --- a/tests/chill.exp +++ b/tests/chill.exp @@ -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; } diff --git a/tests/cplusplus.exp b/tests/cplusplus.exp index 157c869..b4466a0 100644 --- a/tests/cplusplus.exp +++ b/tests/cplusplus.exp @@ -269,5 +269,5 @@ is_reserved_word (str, len) return &wordlist[key]; } } - return 0; + return (struct resword *) 0; } diff --git a/tests/gpc.exp b/tests/gpc.exp index 28b5843..b8d8f3d 100644 --- a/tests/gpc.exp +++ b/tests/gpc.exp @@ -153,5 +153,5 @@ is_reserved_word (register const char *str, register size_t len) return &wordlist[key]; } } - return 0; + return (struct resword *) 0; } diff --git a/tests/incomplete.exp b/tests/incomplete.exp index 4b527ec..6bf4b2a 100644 --- a/tests/incomplete.exp +++ b/tests/incomplete.exp @@ -121,5 +121,5 @@ in_word_set (register const char *str, register size_t len) return &wordlist[key]; } } - return 0; + return (struct month *) 0; } diff --git a/tests/java.exp b/tests/java.exp index f633df1..1b046f6 100644 --- a/tests/java.exp +++ b/tests/java.exp @@ -199,5 +199,5 @@ java_keyword (str, len) return &wordlist[key]; } } - return 0; + return (struct java_keyword *) 0; } diff --git a/tests/languages.exp b/tests/languages.exp index 0a80525..03138cd 100644 --- a/tests/languages.exp +++ b/tests/languages.exp @@ -1495,7 +1495,7 @@ in_word_set (register const char *str, register size_t len) return &wordlist[key]; } } - return 0; + return (struct language *) 0; } diff --git a/tests/modula2.exp b/tests/modula2.exp index 703f188..e4ded2d 100644 --- a/tests/modula2.exp +++ b/tests/modula2.exp @@ -246,5 +246,5 @@ in_word_set (register const char *str, register size_t len) return s; } } - return 0; + return (const char *) 0; } diff --git a/tests/objc.exp b/tests/objc.exp index cad4783..aea0f41 100644 --- a/tests/objc.exp +++ b/tests/objc.exp @@ -194,5 +194,5 @@ is_reserved_word (register const char *str, register size_t len) return &wordlist[key]; } } - return 0; + return (struct resword *) 0; } diff --git a/tests/permut2.exp b/tests/permut2.exp index 551cef4..b4a40be 100644 --- a/tests/permut2.exp +++ b/tests/permut2.exp @@ -104,5 +104,5 @@ in_word_set (register const char *str, register size_t len) return s; } } - return 0; + return (const char *) 0; } diff --git a/tests/permut3.exp b/tests/permut3.exp index e680f34..36df7fc 100644 --- a/tests/permut3.exp +++ b/tests/permut3.exp @@ -104,5 +104,5 @@ in_word_set (register const char *str, register size_t len) return s; } } - return 0; + return (const char *) 0; } diff --git a/tests/permutc2.exp b/tests/permutc2.exp index eb2ac35..3cde2ab 100644 --- a/tests/permutc2.exp +++ b/tests/permutc2.exp @@ -153,5 +153,5 @@ in_word_set (register const char *str, register size_t len) return s; } } - return 0; + return (const char *) 0; } diff --git a/tests/test-4.exp b/tests/test-4.exp index 4822bbc..bdf48a3 100644 --- a/tests/test-4.exp +++ b/tests/test-4.exp @@ -230,5 +230,5 @@ in_word_set (register const char *str, register size_t len) } } } - return 0; + return (struct resword *) 0; }