From 0e200d2a19185dab9d73eee90bd6cd0246416a9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C4=8Cestm=C3=ADr=20Kalina?= Date: Fri, 2 Dec 2022 06:44:09 -0500 Subject: [PATCH] e_os2: add ossl_static_assert_type_eq MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a gcc-only static assertion that a variable is of a specified type. Signed-off-by: Čestmír Kalina Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/12256) --- include/internal/e_os.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/internal/e_os.h b/include/internal/e_os.h index 0455849559c..df5d0b05840 100644 --- a/include/internal/e_os.h +++ b/include/internal/e_os.h @@ -22,6 +22,15 @@ * outside; this file e_os.h is not part of the exported interface. */ +/* ossl_static_assert_type_eq: gcc-only variable type static assertion */ +# if defined(__GNUC__) && !defined(__clang__) +# define ossl_static_assert_type_eq(type, x) \ + _Static_assert((__builtin_types_compatible_p(type, __typeof__(x))), \ + #x " type check failed, expected: " #type) +# else +# define ossl_static_assert_type_eq(type, x) +# endif + # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI) # define NO_CHMOD # define NO_SYSLOG -- 2.47.3