BUILD: compiler: define a __fallthrough statement for switch/case

When the code is preprocessed first and compiled later, such as when
built under distcc, a lot of fallthrough warnings are emitted because
the preprocessor has already stripped the comments.

As an alternative, a "fallthrough" attribute was added with the same
compilers as those which started to emit those warnings. However it's
not portable to older compilers. Let's just define a __fallthrough
statement that corresponds to this attribute on supported compilers
and only switches to the classical empty do {} while (0) on other ones.

This way the code will support being cleaned up using __fallthrough.
This commit is contained in:
Willy Tarreau 2022-11-13 12:21:22 +01:00
parent 2b080f713f
commit 1f344c0f30

View File

@ -60,6 +60,20 @@
#define __has_attribute(x) __equals_1(__has_attribute_ ## x)
#endif
/* The fallthrough attribute arrived with gcc 7, the same version that started
* to emit the fallthrough warnings and to parse the comments. Comments do not
* manage to stop the warning when preprocessing is split from compiling (e.g.
* when building under distcc). Better encourage the use of a __fallthrough
* statement instead. There are still limitations in that clang doesn't accept
* it after a label; this is the reason why we're always preceding it with an
* empty do-while.
*/
#if __has_attribute(fallthrough)
# define __fallthrough do { } while (0); __attribute__((fallthrough))
#else
# define __fallthrough do { } while (0)
#endif
#if !defined(__GNUC__)
/* Some versions of glibc irresponsibly redefine __attribute__() to empty for
* non-gcc compilers, and as such, silently break all constructors with other