warnings: enable -Wuseless-cast, and eliminate warnings

Prompted by Frank Heckenbach.
https://lists.gnu.org/archive/html/bug-bison/2019-11/msg00016.html.

* configure.ac (warn_cxx): Add -Wuseless-cast.
* data/skeletons/c.m4 (b4_attribute_define): Define
YY_IGNORE_USELESS_CAST_BEGIN and YY_IGNORE_USELESS_CAST_END.
* data/skeletons/glr.c (YY_FPRINTF): New, replaces YYFPRINTF, wrapped
with YY_IGNORE_USELESS_CAST_BEGIN and YY_IGNORE_USELESS_CAST_END.
(YY_DPRINTF): Likewise.
* tests/actions.at: Remove useless cast.
* tests/headers.at: Adjust.
This commit is contained in:
Akim Demaille
2019-11-30 09:23:35 +01:00
parent 9e9e49224f
commit f8d82ff039
7 changed files with 153 additions and 100 deletions

View File

@@ -151,8 +151,6 @@ if test "$enable_gcc_warnings" = yes; then
# Warnings for the test suite, and maybe for bison if GCC is modern
# enough.
gl_WARN_ADD([-Wmissing-declarations], [WARN_CFLAGS_TEST])
gl_WARN_ADD([-Wmissing-prototypes], [WARN_CFLAGS_TEST])
test $lv_cv_gcc_pragma_push_works = yes &&
AS_VAR_APPEND([WARN_CFLAGS], [" $WARN_CFLAGS_TEST"])
@@ -179,6 +177,14 @@ if test "$enable_gcc_warnings" = yes; then
[[if (sizeof (long) < sizeof (int)) return 1;]])])
gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
[AC_LANG_PROGRAM([], [nullptr])])
# Before GCC6, the pragmas don't work well enough to neutralize
# this warning.
gl_WARN_ADD([-Wuseless-cast], [WARN_CXXFLAGS],
[AC_LANG_PROGRAM([], [
#if defined __GNUC__ && ! defined __ICC && ! defined __clang__ && __GNUC__ < 6
syntax error
#endif
])])
gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
# Warnings for the test suite only.
for i in $warn_tests;