From bbb869ca80fa299f7888b35134218229521dd0c0 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 13 Aug 2019 15:18:34 -0700 Subject: uhd: Add UHD_FALLTHROUGH attribute This provides a platform-independent attribute to allow fallthroughs in switch statements. Example: switch (foo) { case BAR: do_something(); UHD_FALLTHROUGH case BAZ: do_another_thing(); } The usage of UHD_FALLTHROUGH will avoid a compiler warning if indeed the fallthrough was intentional. The associated warning (-Wimplicit-fallthrough) is only available on gcc and Clang. --- host/include/uhd/config.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index dee0716f4..383159005 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -53,6 +53,7 @@ typedef ptrdiff_t ssize_t; # define UHD_DEPRECATED __declspec(deprecated) # define UHD_ALIGNED(x) __declspec(align(x)) # define UHD_UNUSED(x) x +# define UHD_FALLTHROUGH #elif defined(__MINGW32__) # define UHD_EXPORT __declspec(dllexport) # define UHD_IMPORT __declspec(dllimport) @@ -61,6 +62,7 @@ typedef ptrdiff_t ssize_t; # define UHD_DEPRECATED __declspec(deprecated) # define UHD_ALIGNED(x) __declspec(align(x)) # define UHD_UNUSED(x) x __attribute__((unused)) +# define UHD_FALLTHROUGH #elif defined(__GNUG__) && __GNUG__ >= 4 # define UHD_EXPORT __attribute__((visibility("default"))) # define UHD_IMPORT __attribute__((visibility("default"))) @@ -69,6 +71,11 @@ typedef ptrdiff_t ssize_t; # define UHD_DEPRECATED __attribute__((deprecated)) # define UHD_ALIGNED(x) __attribute__((aligned(x))) # define UHD_UNUSED(x) x __attribute__((unused)) +# if __GNUG__ >= 7 +# define UHD_FALLTHROUGH __attribute__((fallthrough)); +# else +# define UHD_FALLTHROUGH +# endif #elif defined(__clang__) # define UHD_EXPORT __attribute__((visibility("default"))) # define UHD_IMPORT __attribute__((visibility("default"))) @@ -77,6 +84,11 @@ typedef ptrdiff_t ssize_t; # define UHD_DEPRECATED __attribute__((deprecated)) # define UHD_ALIGNED(x) __attribute__((aligned(x))) # define UHD_UNUSED(x) x __attribute__((unused)) +# if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 8) +# define UHD_FALLTHROUGH [[clang:fallthrough]] +# else +# define UHD_FALLTHROUGH +# endif #else # define UHD_EXPORT # define UHD_IMPORT @@ -85,6 +97,7 @@ typedef ptrdiff_t ssize_t; # define UHD_DEPRECATED # define UHD_ALIGNED(x) # define UHD_UNUSED(x) x +# define UHD_FALLTHROUGH #endif // Define API declaration macro -- cgit v1.2.3