mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 05:43:03 +00:00
warning: avoid warnings about unreachable code
Reported by Uxio Prego. https://lists.gnu.org/archive/html/help-bison/2018-11/msg00031.html We also need to move the unreachable 'goto' to a reachable place, otherwise clang complains about the code being unreachable anyway. See also https://bugs.llvm.org/show_bug.cgi?id=39736. Interestingly, we don't have to apply that trick to `#define YYCDEBUG if (false) std::cerr`, clang does not warn when the code comes from macro expansion. * configure.ac: Use -Wunreachable-code when supported. * data/lalr1.cc, data/yacc.c: Pacify clang's warning about `if (0)` by using a macro. Another possibility was to move this statement to a reachable place. * tests/actions.at, tests/c++.at: Avoid generating unreachable code.
This commit is contained in:
12
configure.ac
12
configure.ac
@@ -113,6 +113,7 @@ if test "$enable_gcc_warnings" = yes; then
|
|||||||
-fno-color-diagnostics
|
-fno-color-diagnostics
|
||||||
-Wno-keyword-macro'
|
-Wno-keyword-macro'
|
||||||
|
|
||||||
|
|
||||||
AC_LANG_PUSH([C])
|
AC_LANG_PUSH([C])
|
||||||
# Clang supports many of GCC's -W options, but only issues warnings
|
# Clang supports many of GCC's -W options, but only issues warnings
|
||||||
# on the ones it does not recognize. In that case, gl_WARN_ADD
|
# on the ones it does not recognize. In that case, gl_WARN_ADD
|
||||||
@@ -126,6 +127,11 @@ if test "$enable_gcc_warnings" = yes; then
|
|||||||
# CFLAGS, and restore CFLAGS after the tests.
|
# CFLAGS, and restore CFLAGS after the tests.
|
||||||
save_CFLAGS=$CFLAGS
|
save_CFLAGS=$CFLAGS
|
||||||
gl_WARN_ADD([-Werror=unknown-warning-option], [CFLAGS])
|
gl_WARN_ADD([-Werror=unknown-warning-option], [CFLAGS])
|
||||||
|
# Accept this warning only if it is not too touchy (e.g., clang 3.3
|
||||||
|
# and 3.4).
|
||||||
|
gl_WARN_ADD([-Wunreachable-code], [WARN_CFLAGS],
|
||||||
|
[AC_LANG_PROGRAM([],
|
||||||
|
[[if (sizeof (long) < sizeof (int)) return 1;]])])
|
||||||
for i in $warn_common $warn_c;
|
for i in $warn_common $warn_c;
|
||||||
do
|
do
|
||||||
gl_WARN_ADD([$i], [WARN_CFLAGS])
|
gl_WARN_ADD([$i], [WARN_CFLAGS])
|
||||||
@@ -147,6 +153,7 @@ if test "$enable_gcc_warnings" = yes; then
|
|||||||
CFLAGS=$save_CFLAGS
|
CFLAGS=$save_CFLAGS
|
||||||
AC_LANG_POP([C])
|
AC_LANG_POP([C])
|
||||||
|
|
||||||
|
|
||||||
AC_LANG_PUSH([C++])
|
AC_LANG_PUSH([C++])
|
||||||
save_CXXFLAGS=$CXXFLAGS
|
save_CXXFLAGS=$CXXFLAGS
|
||||||
gl_WARN_ADD([-Werror=unknown-warning-option], [CXXFLAGS])
|
gl_WARN_ADD([-Werror=unknown-warning-option], [CXXFLAGS])
|
||||||
@@ -154,6 +161,11 @@ if test "$enable_gcc_warnings" = yes; then
|
|||||||
do
|
do
|
||||||
gl_WARN_ADD([$i], [WARN_CXXFLAGS])
|
gl_WARN_ADD([$i], [WARN_CXXFLAGS])
|
||||||
done
|
done
|
||||||
|
# Accept this warning only if it is not too touchy (e.g., clang 3.3
|
||||||
|
# and 3.4).
|
||||||
|
gl_WARN_ADD([-Wunreachable-code], [WARN_CXXFLAGS],
|
||||||
|
[AC_LANG_PROGRAM([],
|
||||||
|
[[if (sizeof (long) < sizeof (int)) return 1;]])])
|
||||||
gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
|
gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
|
||||||
[AC_LANG_PROGRAM([], [nullptr])])
|
[AC_LANG_PROGRAM([], [nullptr])])
|
||||||
gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
|
gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
|
||||||
|
|||||||
@@ -971,11 +971,11 @@ b4_dollar_popdef])[]dnl
|
|||||||
| yyerrorlab -- error raised explicitly by YYERROR. |
|
| yyerrorlab -- error raised explicitly by YYERROR. |
|
||||||
`---------------------------------------------------*/
|
`---------------------------------------------------*/
|
||||||
yyerrorlab:
|
yyerrorlab:
|
||||||
/* Pacify compilers like GCC when the user code never invokes
|
/* Pacify compilers when the user code never invokes YYERROR and
|
||||||
YYERROR and the label yyerrorlab therefore never appears in user
|
the label yyerrorlab therefore never appears in user code. */
|
||||||
code. */
|
|
||||||
if (false)
|
if (false)
|
||||||
goto yyerrorlab;
|
YYERROR;
|
||||||
|
|
||||||
/* Do not reclaim the symbols of the rule whose action triggered
|
/* Do not reclaim the symbols of the rule whose action triggered
|
||||||
this YYERROR. */
|
this YYERROR. */
|
||||||
yypop_ (yylen);
|
yypop_ (yylen);
|
||||||
|
|||||||
@@ -1777,11 +1777,10 @@ yyerrlab:
|
|||||||
| yyerrorlab -- error raised explicitly by YYERROR. |
|
| yyerrorlab -- error raised explicitly by YYERROR. |
|
||||||
`---------------------------------------------------*/
|
`---------------------------------------------------*/
|
||||||
yyerrorlab:
|
yyerrorlab:
|
||||||
/* Pacify compilers like GCC when the user code never invokes
|
/* Pacify compilers when the user code never invokes YYERROR and the
|
||||||
YYERROR and the label yyerrorlab therefore never appears in user
|
label yyerrorlab therefore never appears in user code. */
|
||||||
code. */
|
|
||||||
if (0)
|
if (0)
|
||||||
goto yyerrorlab;
|
YYERROR;
|
||||||
|
|
||||||
/* Do not reclaim the symbols of the rule whose action triggered
|
/* Do not reclaim the symbols of the rule whose action triggered
|
||||||
this YYERROR. */
|
this YYERROR. */
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
# Don't depend on $(BISON) otherwise we would rebuild these files
|
# Don't depend on $(BISON) otherwise we would rebuild these files
|
||||||
# in srcdir, including during distcheck, which is forbidden.
|
# in srcdir, including during distcheck, which is forbidden.
|
||||||
%D%/parser.stamp: $(BISON_IN)
|
%D%/parser.stamp: $(BISON_IN) $(dist_pkgdata_DATA)
|
||||||
SUFFIXES += .yy .stamp
|
SUFFIXES += .yy .stamp
|
||||||
.yy.stamp:
|
.yy.stamp:
|
||||||
$(AM_V_YACC)rm -f $@
|
$(AM_V_YACC)rm -f $@
|
||||||
|
|||||||
@@ -519,6 +519,8 @@ AT_DATA_GRAMMAR([[input.y]],
|
|||||||
#define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
|
#define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
|
||||||
[(Location).first_line, (Location).last_line])[
|
[(Location).first_line, (Location).last_line])[
|
||||||
|
|
||||||
|
#define USE(SYM)
|
||||||
|
|
||||||
/* Display the symbol type Symbol. */
|
/* Display the symbol type Symbol. */
|
||||||
#define V(Symbol, Value, Location, Sep) \
|
#define V(Symbol, Value, Location, Sep) \
|
||||||
fprintf (stderr, #Symbol " (%d@%d-%d)%s", Value, RANGE(Location), Sep)
|
fprintf (stderr, #Symbol " (%d@%d-%d)%s", Value, RANGE(Location), Sep)
|
||||||
@@ -610,8 +612,8 @@ input:
|
|||||||
;
|
;
|
||||||
|
|
||||||
check-spontaneous-errors:
|
check-spontaneous-errors:
|
||||||
raise { abort(); $$ = $1; }
|
raise { abort(); USE(($$, $1)); }
|
||||||
| '(' raise ')' { abort(); $$ = $2; }
|
| '(' raise ')' { abort(); USE(($$, $2)); }
|
||||||
| error
|
| error
|
||||||
{
|
{
|
||||||
$$ = 5;
|
$$ = 5;
|
||||||
|
|||||||
@@ -435,8 +435,6 @@ namespace yy
|
|||||||
return parser::token::TEXT;]])[
|
return parser::token::TEXT;]])[
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abort ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user