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

Avoid "implicit fallthrough" warnings in the generated code.

This commit is contained in:
Bruno Haible
2018-07-26 02:00:39 +02:00
parent 13c9383b10
commit 0d37a8763d
11 changed files with 298 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/* Output routines.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007, 2009, 2011-2012, 2016 Free Software Foundation, Inc.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007, 2009, 2011-2012, 2016, 2018 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -932,6 +932,15 @@ Output::output_hash_function () const
else
{
/* We've got to use the correct, but brute force, technique. */
/* Pseudo-statement or comment that avoids a compiler warning or
lint warning. */
const char * const fallthrough_marker =
"#if defined __cplusplus && __cplusplus >= 201703L\n"
" [[fallthrough]];\n"
"#elif defined __GNUC__ && __GNUC__ >= 7\n"
" __attribute__ ((__fallthrough__));\n"
"#endif\n"
" /*FALLTHROUGH*/\n";
/* It doesn't really matter whether hval is an 'int' or
'unsigned int', but 'unsigned int' gives fewer warnings. */
printf (" %sunsigned int hval = %s;\n\n"
@@ -951,7 +960,7 @@ Output::output_hash_function () const
do
{
if (i > key_pos)
printf (" /*FALLTHROUGH*/\n"); /* Pacify lint. */
printf ("%s", fallthrough_marker);
for ( ; i > key_pos; i--)
printf (" case %d:\n", i);
@@ -964,7 +973,7 @@ Output::output_hash_function () const
while (key_pos != PositionIterator::EOS && key_pos != Positions::LASTCHAR);
if (i >= _min_key_len)
printf (" /*FALLTHROUGH*/\n"); /* Pacify lint. */
printf ("%s", fallthrough_marker);
for ( ; i >= _min_key_len; i--)
printf (" case %d:\n", i);
}