]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
e_os2: add ossl_static_assert_type_eq
authorČestmír Kalina <ckalina@redhat.com>
Fri, 2 Dec 2022 11:44:09 +0000 (06:44 -0500)
committerPauli <pauli@openssl.org>
Fri, 17 Mar 2023 00:12:47 +0000 (11:12 +1100)
Add a gcc-only static assertion that a variable is of a specified type.

Signed-off-by: Čestmír Kalina <ckalina@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12256)

include/internal/e_os.h

index 0455849559ce239b1fdcaffdd59d59ef5e489f0f..df5d0b058406ddd304c177389401c7a876e6c32f 100644 (file)
  * 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