mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
Avoid "gcc -Wmissing-field-initializers" warnings on the generated code.
* src/options.h (Options::has_initializer_suffix): New declaration. * src/options.cc (Options::has_initializer_suffix): New function. * src/output.cc (Output::output_keyword_table): If option -t is specified and option -F is not specified, emit '#pragma GCC diagnostic' lines, to silence -Wmissing-field-initializers warnings from gcc or clang. * tests/charsets.exp: Update. * tests/gpc.exp: Likewise. * tests/incomplete.exp: Likewise. * tests/languages.exp: Likewise. * tests/objc.exp: Likewise. * tests/test-4.exp: Likewise.
This commit is contained in:
16
ChangeLog
16
ChangeLog
@@ -1,3 +1,19 @@
|
||||
2023-09-05 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
Avoid "gcc -Wmissing-field-initializers" warnings on the generated code.
|
||||
* src/options.h (Options::has_initializer_suffix): New declaration.
|
||||
* src/options.cc (Options::has_initializer_suffix): New function.
|
||||
* src/output.cc (Output::output_keyword_table): If option -t is
|
||||
specified and option -F is not specified, emit '#pragma GCC diagnostic'
|
||||
lines, to silence -Wmissing-field-initializers warnings from gcc or
|
||||
clang.
|
||||
* tests/charsets.exp: Update.
|
||||
* tests/gpc.exp: Likewise.
|
||||
* tests/incomplete.exp: Likewise.
|
||||
* tests/languages.exp: Likewise.
|
||||
* tests/objc.exp: Likewise.
|
||||
* tests/test-4.exp: Likewise.
|
||||
|
||||
2023-07-08 Bruno Haible <bruno@clisp.org>
|
||||
|
||||
Avoid "gcc -Wunused-parameter" warnings on the generated hash function.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Handles parsing the Options provided to the user.
|
||||
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2009, 2011, 2016-2018, 2022 Free Software Foundation, Inc.
|
||||
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2009, 2011, 2016-2018, 2022-2023 Free Software Foundation, Inc.
|
||||
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
|
||||
and Bruno Haible <bruno@clisp.org>.
|
||||
|
||||
@@ -627,6 +627,13 @@ Options::set_slot_name (const char *name)
|
||||
_slot_name = name;
|
||||
}
|
||||
|
||||
/* Returns true if the struct initializer suffix has been set. */
|
||||
bool
|
||||
Options::has_initializer_suffix () const
|
||||
{
|
||||
return _initializer_suffix != DEFAULT_INITIALIZER_SUFFIX;
|
||||
}
|
||||
|
||||
/* Sets the struct initializer suffix, if not already set. */
|
||||
void
|
||||
Options::set_initializer_suffix (const char *initializers)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/* Handles parsing the Options provided to the user.
|
||||
|
||||
Copyright (C) 1989-1998, 2000, 2002-2004, 2011 Free Software Foundation, Inc.
|
||||
Copyright (C) 1989-1998, 2000, 2002-2004, 2011, 2023 Free Software Foundation, Inc.
|
||||
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
|
||||
and Bruno Haible <bruno@clisp.org>.
|
||||
|
||||
@@ -174,6 +174,8 @@ public:
|
||||
|
||||
/* Returns the struct initializer suffix. */
|
||||
const char * get_initializer_suffix () const;
|
||||
/* Returns true if the struct initializer suffix has been set. */
|
||||
bool has_initializer_suffix () const;
|
||||
/* Sets the struct initializer suffix, if not already set. */
|
||||
void set_initializer_suffix (const char *initializers);
|
||||
|
||||
|
||||
@@ -1286,6 +1286,20 @@ Output::output_keyword_table () const
|
||||
int index;
|
||||
KeywordExt_List *temp;
|
||||
|
||||
/* Avoid compiler warnings "warning: missing initializer for field ..."
|
||||
for each of the blank entries. */
|
||||
bool silence_missing_initializer_warning =
|
||||
option[TYPE] && !option.has_initializer_suffix();
|
||||
const char *preprocessor_condition =
|
||||
"(defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)";
|
||||
if (silence_missing_initializer_warning)
|
||||
{
|
||||
printf ("#if %s\n", preprocessor_condition);
|
||||
printf ("#pragma GCC diagnostic push\n");
|
||||
printf ("#pragma GCC diagnostic ignored \"-Wmissing-field-initializers\"\n");
|
||||
printf ("#endif\n");
|
||||
}
|
||||
|
||||
printf ("%sstatic ",
|
||||
indent);
|
||||
output_const_type (const_readonly_array, _wordlist_eltype);
|
||||
@@ -1341,7 +1355,15 @@ Output::output_keyword_table () const
|
||||
if (index > 0)
|
||||
printf ("\n");
|
||||
|
||||
printf ("%s };\n\n", indent);
|
||||
printf ("%s };\n", indent);
|
||||
|
||||
if (silence_missing_initializer_warning)
|
||||
{
|
||||
printf ("#if %s\n", preprocessor_condition);
|
||||
printf ("#pragma GCC diagnostic pop\n");
|
||||
printf ("#endif\n");
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@@ -196,6 +196,10 @@ hash (register const char *str, register size_t len)
|
||||
return hval + asso_values[(unsigned char)str[len - 1]];
|
||||
}
|
||||
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
static const struct charset wordlist[] =
|
||||
{
|
||||
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
||||
@@ -1855,6 +1859,9 @@ static const struct charset wordlist[] =
|
||||
{""},
|
||||
{"hp-desktop", 2021}
|
||||
};
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
const struct charset *
|
||||
in_word_set (register const char *str, register size_t len)
|
||||
|
||||
@@ -93,6 +93,10 @@ hash (register const char *str, register size_t len)
|
||||
struct resword *
|
||||
is_reserved_word (register const char *str, register size_t len)
|
||||
{
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
static struct resword wordlist[] =
|
||||
{
|
||||
{""}, {""},
|
||||
@@ -133,6 +137,9 @@ is_reserved_word (register const char *str, register size_t len)
|
||||
{"Goto", GOTO, PASCAL_ISO},
|
||||
{"Begin", BEGIN_, PASCAL_ISO}
|
||||
};
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
||||
{
|
||||
|
||||
@@ -83,6 +83,10 @@ hash (register const char *str, register size_t len)
|
||||
struct month *
|
||||
in_word_set (register const char *str, register size_t len)
|
||||
{
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
static struct month wordlist[] =
|
||||
{
|
||||
{""}, {""}, {""},
|
||||
@@ -101,6 +105,9 @@ in_word_set (register const char *str, register size_t len)
|
||||
{""}, {""}, {""},
|
||||
{"february", 2, 28, 29}
|
||||
};
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
||||
{
|
||||
|
||||
@@ -127,6 +127,10 @@ hash (register const char *str, register size_t len)
|
||||
return hval + asso_values[(unsigned char)str[len - 1]];
|
||||
}
|
||||
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
static const struct language wordlist[] =
|
||||
{
|
||||
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
||||
@@ -1472,6 +1476,9 @@ static const struct language wordlist[] =
|
||||
{""}, {""}, {""}, {""}, {""}, {""}, {""},
|
||||
{"ile", "Interlingue", 181, "interlingue", 181}
|
||||
};
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
const struct language *
|
||||
in_word_set (register const char *str, register size_t len)
|
||||
|
||||
@@ -101,6 +101,10 @@ hash (register const char *str, register size_t len)
|
||||
struct resword *
|
||||
is_reserved_word (register const char *str, register size_t len)
|
||||
{
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
static struct resword wordlist[] =
|
||||
{
|
||||
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
||||
@@ -174,6 +178,9 @@ is_reserved_word (register const char *str, register size_t len)
|
||||
{""}, {""}, {""}, {""}, {""},
|
||||
{"void", TYPESPEC, RID_VOID}
|
||||
};
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
||||
{
|
||||
|
||||
@@ -84,6 +84,10 @@ hash (register const char *str, register size_t len)
|
||||
struct resword *
|
||||
in_word_set (register const char *str, register size_t len)
|
||||
{
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
static struct resword wordlist[] =
|
||||
{
|
||||
{"else", ELSE, NORID},
|
||||
@@ -170,6 +174,9 @@ in_word_set (register const char *str, register size_t len)
|
||||
{"id", OBJECTNAME, RID_ID},
|
||||
{"in", TYPE_QUAL, RID_IN}
|
||||
};
|
||||
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 6) > 4) || (defined __clang__ && __clang_major__ >= 3)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
static short lookup[] =
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user