SQLite Forum

Fix explicit fallthrough protection
Login

Fix explicit fallthrough protection

(1) By Richard (backyardsilks) on 2024-07-01 18:01:26 [source]

sqlite/src/sqliteInt.h contains the code

#if GCC_VERSION>=7000000
# define deliberate_fall_through __attribute__((fallthrough));
#else
# define deliberate_fall_through
#endif

This is great because it means -Wimplicit-fallthrough (or equivalent) can be used with GCC to provide warnings for implicit fallthroughs, which are a frequent source of bugs.

However, this won't do anything for LLVM and that makes it challenging to integrate sqlite into a codebase where -Wimplicit-fallthrough is enabled everywhere. The following alternative should work with both GCC and LLVM:

#ifndef deliberate_fall_through
#  if defined __has_attribute
#    if __has_attribute (fallthrough)
#      define deliberate_fall_through __attribute__ ((fallthrough))
#    else
#      define deliberate_fall_through
#    endif
#  endif
#endif

(2) By Richard (backyardsilks) on 2024-07-02 13:28:28 in reply to 1 [link] [source]

Oops, that should be:

#ifndef deliberate_fall_through
#  if defined __has_attribute
#    if __has_attribute (fallthrough)
#      define deliberate_fall_through __attribute__ ((fallthrough))
#    else
#      define deliberate_fall_through
#    endif
#  else
#    define deliberate_fall_through
#  endif
#endif

(3) By Richard Hipp (drh) on 2024-07-02 13:56:07 in reply to 2 [link] [source]

I implemented the change in a third way: https://sqlite.org/src/info/fc248a4a0a232a95