diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-08-13 15:18:34 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-08-16 11:29:49 -0700 |
commit | bbb869ca80fa299f7888b35134218229521dd0c0 (patch) | |
tree | 75ea1a02c7974bb1688de8d4655cc2e3a9005ff2 /host/include | |
parent | 0280a82aa00f340bf7de11f97fafc11424ba4f1e (diff) | |
download | uhd-bbb869ca80fa299f7888b35134218229521dd0c0.tar.gz uhd-bbb869ca80fa299f7888b35134218229521dd0c0.tar.bz2 uhd-bbb869ca80fa299f7888b35134218229521dd0c0.zip |
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.
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/config.hpp | 13 |
1 files changed, 13 insertions, 0 deletions
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 |