[c99, cpp]: Use fallthrough attribute
This uncovers a small issue when compiling with CLang:
/bin/sh ../libtool --tag=CC --mode=link clang -g -O2 -o stage1flex stage1flex-scan.o stage1flex-buf.o stage1flex-ccl.o stage1flex-dfa.o stage1flex-ecs.o stage1flex-filter.o stage1flex-gen.o stage1flex-main.o stage1flex-misc.o stage1flex-nfa.o stage1flex-options.o stage1flex-parse.o stage1flex-regex.o stage1flex-scanflags.o stage1flex-scanopt.o stage1flex-skeletons.o stage1flex-sym.o stage1flex-tables.o stage1flex-tables_shared.o stage1flex-tblcmp.o stage1flex-yylex.o -lm
libtool: link: clang -g -O2 -o stage1flex stage1flex-scan.o stage1flex-buf.o stage1flex-ccl.o stage1flex-dfa.o stage1flex-ecs.o stage1flex-filter.o stage1flex-gen.o stage1flex-main.o stage1flex-misc.o stage1flex-nfa.o stage1flex-options.o stage1flex-parse.o stage1flex-regex.o stage1flex-scanflags.o stage1flex-scanopt.o stage1flex-skeletons.o stage1flex-sym.o stage1flex-tables.o stage1flex-tables_shared.o stage1flex-tblcmp.o stage1flex-yylex.o -lm
( cd . && /mnt/store/flex-clang/src/stage1flex \
-o scan.c -t scan.l ) >stage1scan.c || \
{ s=$?; rm -f stage1scan.c; exit $s; }
depbase=`echo stage1scan.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
clang -DHAVE_CONFIG_H -I. -DLOCALEDIR=\"/usr/share/locale\" -g -O2 -MT stage1scan.o -MD -MP -MF $depbase.Tpo -c -o stage1scan.o stage1scan.c &&\
mv -f $depbase.Tpo $depbase.Po
scan.c:5240:2: error: fallthrough annotation does not directly precede switch label
5240 | __attribute__((fallthrough));
| ^
Here's the generated code:
stage1scan.c:
case YY_STATE_EOF(OPTION):
#ifdef __clang__
__attribute__((fallthrough));
#endif
/* FALLTHROUGH */
case YY_STATE_EOF(LINEDIR):
#ifdef __clang__
__attribute__((fallthrough));
#endif
/* FALLTHROUGH */ /* issue: FALLTHROUGH but there's a statement below */
yyterminate();
case YY_END_OF_BUFFER:
{
/* Amount of text matched not including the EOB char. */
int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
The error should happen also with GCC should we use [[fallthrough]] (since C++17, C23)
Fixes https://github.com/westes/flex/issues/427
Please use the hooks instead of defining new yy* functions in C. We're in the process of making the skeleton code generation language agnostic.
You can still include the feature check in the macro definition. Quoting can be a little is all.
Thanks! I have also fixed the build error by not emitting EOF_STATE_CASE_FALLTHROUGH before EOF_STATE_CASE_TERMINATE: https://github.com/westes/flex/pull/709/commits/0aac7c32.
An other way is to add an explicit EOF_STATE_CASE_FALLTHROUGH_TO_TERMINATE