diff options
author | James McCoy <jamessan@jamessan.com> | 2017-05-03 00:08:10 -0400 |
---|---|---|
committer | James McCoy <jamessan@jamessan.com> | 2017-05-12 17:07:25 -0400 |
commit | 5ec72aadbf51a729969cb7f9f06cf573fc77da59 (patch) | |
tree | fd459b0cf4759b3d37fe098aafb8f560674ffb85 /src/nvim/macros.h | |
parent | b43a3dbff8c615fec152e3fb2157961f3d90b705 (diff) | |
download | rneovim-5ec72aadbf51a729969cb7f9f06cf573fc77da59.tar.gz rneovim-5ec72aadbf51a729969cb7f9f06cf573fc77da59.tar.bz2 rneovim-5ec72aadbf51a729969cb7f9f06cf573fc77da59.zip |
*: Use __attribute__((fallthrough)) where comments aren't supported
Although GCC now detects possibly unintentional fall through, there
rules around which the comments are detected are rather strict. In
cases where a comment isn't detected, upstream [recommends] using their
fallthrough attribute.
[recommends]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77817#c11
Diffstat (limited to 'src/nvim/macros.h')
-rw-r--r-- | src/nvim/macros.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 214af82422..9ab6dc5d2b 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -153,4 +153,22 @@ #define STR_(x) #x #define STR(x) STR_(x) +#ifndef __has_attribute +# define NVIM_HAS_ATTRIBUTE(x) 0 +#elif defined(__clang__) && __clang__ == 1 \ + && (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ <= 5)) +// Starting in Clang 3.6, __has_attribute was fixed to only report true for +// GNU-style attributes. Prior to that, it reported true if _any_ backend +// supported the attribute. +# define NVIM_HAS_ATTRIBUTE(x) 0 +#else +# define NVIM_HAS_ATTRIBUTE __has_attribute +#endif + +#if NVIM_HAS_ATTRIBUTE(fallthrough) +# define FALLTHROUGH __attribute__((fallthrough)) +#else +# define FALLTHROUGH +#endif + #endif // NVIM_MACROS_H |