util: add a FALLTROUGH macro

Not all compilers support __atttribute__((fallthrough)) so use a macro.

v2: use C++17 / C18 standard attribute (Tony Wasserka)

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> (v1)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7747>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-11-24 18:02:49 +01:00
parent a5b899c7da
commit 5e7c00aacb

View file

@ -72,5 +72,18 @@
#define IEEE_ONE 0x3f800000
#ifndef __has_attribute
# define __has_attribute(x) 0
#endif
#if __cplusplus >= 201703L || __STDC_VERSION__ >= 201710L
/* Standard C++17/C18 attribute */
#define FALLTHROUGH [[fallthrough]]
#elif __has_attribute(fallthrough)
/* Non-standard but supported by at least gcc and clang */
#define FALLTHROUGH __attribute__((fallthrough))
#else
#define FALLTHROUGH do { } while(0)
#endif
#endif /* COMPILER_H */