Skip to content

Commit f8d82ff

Browse files
committed
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.
1 parent 9e9e492 commit f8d82ff

File tree

7 files changed

+153
-100
lines changed

7 files changed

+153
-100
lines changed

TODO

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
* Bison 3.5
2+
** Deprecate YYPRINT
3+
The doc shows it too much.
4+
5+
** glr.c: parse.assert
6+
There are many assertions in glr.c that are there to check the skeleton
7+
itself, not the user code. So it should be under the control of
8+
parse.assert.
9+
10+
** java, d: error.verbose
11+
The code checks dynamically for error.verbose. It should be controlled by
12+
M4.
13+
214
** doc
315
I feel its ugly to use the GNU style to declare functions in the doc. It
416
generates tons of white space in the page, and may contribute to bad page

configure.ac

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ if test "$enable_gcc_warnings" = yes; then
151151

152152
# Warnings for the test suite, and maybe for bison if GCC is modern
153153
# enough.
154-
gl_WARN_ADD([-Wmissing-declarations], [WARN_CFLAGS_TEST])
155-
gl_WARN_ADD([-Wmissing-prototypes], [WARN_CFLAGS_TEST])
156154
test $lv_cv_gcc_pragma_push_works = yes &&
157155
AS_VAR_APPEND([WARN_CFLAGS], [" $WARN_CFLAGS_TEST"])
158156

@@ -179,6 +177,14 @@ if test "$enable_gcc_warnings" = yes; then
179177
[[if (sizeof (long) < sizeof (int)) return 1;]])])
180178
gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
181179
[AC_LANG_PROGRAM([], [nullptr])])
180+
# Before GCC6, the pragmas don't work well enough to neutralize
181+
# this warning.
182+
gl_WARN_ADD([-Wuseless-cast], [WARN_CXXFLAGS],
183+
[AC_LANG_PROGRAM([], [
184+
#if defined __GNUC__ && ! defined __ICC && ! defined __clang__ && __GNUC__ < 6
185+
syntax error
186+
#endif
187+
])])
182188
gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
183189
# Warnings for the test suite only.
184190
for i in $warn_tests;

data/skeletons/c.m4

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ m4_define([b4_attribute_define],
327327
328328
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
329329
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
330-
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
331-
_Pragma ("GCC diagnostic push") \
332-
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
330+
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
331+
_Pragma ("GCC diagnostic push") \
332+
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
333333
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
334-
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
334+
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
335335
_Pragma ("GCC diagnostic pop")
336336
#else
337337
# define YY_INITIAL_VALUE(Value) Value
@@ -343,6 +343,18 @@ m4_define([b4_attribute_define],
343343
#ifndef YY_INITIAL_VALUE
344344
# define YY_INITIAL_VALUE(Value) /* Nothing. */
345345
#endif
346+
347+
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
348+
# define YY_IGNORE_USELESS_CAST_BEGIN \
349+
_Pragma ("GCC diagnostic push") \
350+
_Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
351+
# define YY_IGNORE_USELESS_CAST_END \
352+
_Pragma ("GCC diagnostic pop")
353+
#endif
354+
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
355+
# define YY_IGNORE_USELESS_CAST_BEGIN
356+
# define YY_IGNORE_USELESS_CAST_END
357+
#endif
346358
]])
347359

348360

0 commit comments

Comments
 (0)