c, c++: avoid implicit fall-throw

Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00004.html

* configure.ac (warn_common): Add -Wimplicit-fallthrough.
This does trigger failures in the test suite.
* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c, tests/c++.at:
Make fall-throws explicit.
This commit is contained in:
Akim Demaille
2019-01-15 07:43:16 +01:00
parent a049509d04
commit ad326ada91
6 changed files with 38 additions and 5 deletions

View File

@@ -96,7 +96,8 @@ AM_CONDITIONAL([ENABLE_GCC_WARNINGS], [test "$enable_gcc_warnings" = yes])
if test "$enable_gcc_warnings" = yes; then if test "$enable_gcc_warnings" = yes; then
warn_common='-Wall -Wextra -Wno-sign-compare -Wcast-align warn_common='-Wall -Wextra -Wno-sign-compare -Wcast-align
-fparse-all-comments -Wdocumentation -fparse-all-comments -Wdocumentation
-Wformat -Wnull-dereference -Wpointer-arith -Wshadow -Wformat -Wimplicit-fallthrough -Wnull-dereference
-Wpointer-arith -Wshadow
-Wundefined-func-template -Wwrite-strings' -Wundefined-func-template -Wwrite-strings'
warn_c='-Wbad-function-cast -Wstrict-prototypes' warn_c='-Wbad-function-cast -Wstrict-prototypes'
warn_cxx='-Wextra-semi -Wnoexcept' warn_cxx='-Wextra-semi -Wnoexcept'

View File

@@ -590,7 +590,10 @@ yytnamerr (char *yyres, const char *yystr)
case '\\': case '\\':
if (*++yyp != '\\') if (*++yyp != '\\')
goto do_not_strip_quotes; goto do_not_strip_quotes;
/* Fall through. */ else
goto append;
append:
default: default:
if (yyres) if (yyres)
yyres[yyn] = *yyp; yyres[yyn] = *yyp;

View File

@@ -532,7 +532,10 @@ m4_if(b4_prefix, [yy], [],
case '\\': case '\\':
if (*++yyp != '\\') if (*++yyp != '\\')
goto do_not_strip_quotes; goto do_not_strip_quotes;
// Fall through. else
goto append;
append:
default: default:
yyr += *yyp; yyr += *yyp;
break; break;

View File

@@ -1066,7 +1066,10 @@ yytnamerr (char *yyres, const char *yystr)
case '\\': case '\\':
if (*++yyp != '\\') if (*++yyp != '\\')
goto do_not_strip_quotes; goto do_not_strip_quotes;
/* Fall through. */ else
goto append;
append:
default: default:
if (yyres) if (yyres)
yyres[yyn] = *yyp; yyres[yyn] = *yyp;

View File

@@ -6650,6 +6650,28 @@ For example, if you use @samp{%define api.prefix @{c@}}, the names become
@code{cparse}, @code{clex}, @dots{}, @code{CSTYPE}, @code{CLTYPE}, and so @code{cparse}, @code{clex}, @dots{}, @code{CSTYPE}, @code{CLTYPE}, and so
on. on.
Users of Flex must update the signature of the generated @code{yylex}
function. Since the Flex scanner usually includes the generated header of
the parser (to get the definitions of the tokens, etc.), the most convenient
way is to insert the declaration of @code{yylex} in the @code{provides}
section:
@example
%define api.prefix @{c@}
// Emitted in the header file, after the definition of YYSTYPE.
%code provides
@{
// Tell Flex the expected prototype of yylex.
#define YY_DECL \
int clex (CSTYPE*y ylval, CLTYPE *yylloc)
// Declare the scanner.
YY_DECL;
@}
@end example
@sp 1
The @code{%define} variable @code{api.prefix} works in two different ways. The @code{%define} variable @code{api.prefix} works in two different ways.
In the implementation file, it works by adding macro definitions to the In the implementation file, it works by adding macro definitions to the
beginning of the parser implementation file, defining @code{yyparse} as beginning of the parser implementation file, defining @code{yyparse} as

View File

@@ -1242,7 +1242,8 @@ yylex (yy::parser::semantic_type *lvalp)
default: default:
lvalp->]AT_VARIANT_IF([build<Object> (res)], lvalp->]AT_VARIANT_IF([build<Object> (res)],
[obj = new Object (res)])[; [obj = new Object (res)])[;
// Fall through. goto zero;
zero:
case 0: case 0:
return res; return res;
} }