From 904c1b4d699aeb1ce170f0cd996a01d2d06812e3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Sep 2021 20:11:46 -0400 Subject: 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. --- include/zix/attributes.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/zix/attributes.h') 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 + /** @} */ -- cgit v1.2.1