diff options
author | David Robillard <d@drobilla.net> | 2021-09-10 20:11:46 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-09-10 20:54:28 -0400 |
commit | 904c1b4d699aeb1ce170f0cd996a01d2d06812e3 (patch) | |
tree | 35a4a9f75a395a958ab0ea5fffeca81ce733bbc1 /include/zix/attributes.h | |
parent | 1f8c8118f2d42f495dbe6e3adb2a95c87a92e8e0 (diff) | |
download | zix-904c1b4d699aeb1ce170f0cd996a01d2d06812e3.tar.gz zix-904c1b4d699aeb1ce170f0cd996a01d2d06812e3.tar.bz2 zix-904c1b4d699aeb1ce170f0cd996a01d2d06812e3.zip |
Add nullability annotations
This allows clang to issue warnings at compile time when null is passed to a
non-null parameter. For public entry points, also add assertions to catch such
issues when the compiler does not support this.
Diffstat (limited to 'include/zix/attributes.h')
-rw-r--r-- | include/zix/attributes.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/zix/attributes.h b/include/zix/attributes.h index c8f77c4..255b315 100644 --- a/include/zix/attributes.h +++ b/include/zix/attributes.h @@ -74,6 +74,17 @@ # define ZIX_UNUSED(name) name #endif +// Clang nullability annotations +#if defined(__clang__) && __clang_major__ >= 7 +# define ZIX_NONNULL _Nonnull +# define ZIX_NULLABLE _Nullable +# define ZIX_ALLOCATED _Null_unspecified +#else +# define ZIX_NONNULL +# define ZIX_NULLABLE +# define ZIX_ALLOCATED +#endif + /** @} */ |