wolfssl/wolfcrypt/types.h: refactor static_assert*() as wc_static_assert*() to avoid conflicts with target-native static_assert(), and add additional coverage for C23 and MSVC C11.

wolfcrypt/test/test.c: in render_error_message(), in tests for strerror_r(), test for __USE_GNU.
This commit is contained in:
Daniel Pouzzner 2024-10-04 16:41:33 -05:00
parent 898815f11b
commit a25c0244a7
4 changed files with 34 additions and 33 deletions

View File

@ -71,7 +71,7 @@ typedef struct Dtls13HandshakeHeader {
byte fragmentLength[3];
} Dtls13HandshakeHeader;
static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);
wc_static_assert(sizeof(Dtls13HandshakeHeader) == DTLS13_HANDSHAKE_HEADER_SZ);
/**
* struct Dtls13Recordplaintextheader: represent header of unprotected DTLSv1.3

View File

@ -841,11 +841,11 @@ static void render_error_message(const char* msg, wc_test_ret_t es)
* stores an error string in the supplied buffer. this is all most
* infelicitous...
*/
#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
#if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
((defined(__GLIBC__) && (__GLIBC__ >= 2)) || \
(defined(__USE_XOPEN2K) && \
defined(_POSIX_C_SOURCE) && \
((defined(__GLIBC__) && (__GLIBC__ >= 2) && defined(__USE_GNU)) || \
(defined(__USE_XOPEN2K) && \
defined(_POSIX_C_SOURCE) && \
(_POSIX_C_SOURCE >= 200112L)))
char errno_buf[64], *errno_string;

View File

@ -20,24 +20,17 @@
*/
/*
* ************************************************************************
* Note, this file should not be edited to activate/deactivate features.
*
* ******************************** NOTICE ********************************
*
* ************************************************************************
*
* This method of uncommenting a line in settings.h is outdated.
*
* Please use user_settings.h / WOLFSSL_USER_SETTINGS
* Instead, add/edit user_settings.h, and compile with -DWOLFSSL_USER_SETTINGS
*
* or
*
* ./configure CFLAGS="-DFLAG"
* ./configure CFLAGS="-DFEATURE_FLAG_TO_DEFINE -UFEATURE_FLAG_TO_CLEAR [...]"
*
* For more information see:
*
* https://www.wolfssl.com/how-do-i-manage-the-build-configuration-of-wolfssl/
*
*/

View File

@ -1693,15 +1693,22 @@ typedef struct w64wrapper {
#define PRAGMA_DIAG_POP /* null expansion */
#endif
#define WC_CPP_CAT_(a, b) a ## b
#define WC_CPP_CAT(a, b) WC_CPP_CAT_(a, b)
#if (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
#ifndef static_assert2
#define static_assert2 static_assert
#endif
#elif !defined(static_assert)
#if !defined(__cplusplus) && \
#ifndef wc_static_assert
#if (defined(__cplusplus) && (__cplusplus >= 201703L)) || \
(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)) || \
(defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
/* directly usable variadic declaration */
#define wc_static_assert static_assert
#ifndef wc_static_assert2
#define wc_static_assert2 static_assert
#endif
#elif defined(_MSC_VER) && (__STDC_VERSION__ >= 201112L)
/* native 2-argument static_assert() */
#define wc_static_assert(expr) static_assert(expr, #expr)
#ifndef wc_static_assert2
#define wc_static_assert2(expr, msg) static_assert(expr, msg)
#endif
#elif !defined(__cplusplus) && \
!defined(__STRICT_ANSI__) && \
!defined(WOLF_C89) && \
defined(__STDC_VERSION__) && \
@ -1709,19 +1716,20 @@ typedef struct w64wrapper {
((defined(__GNUC__) && \
(__GNUC__ >= 5)) || \
defined(__clang__))
#define static_assert(expr) _Static_assert(expr, #expr)
#ifndef static_assert2
#define static_assert2(expr, msg) _Static_assert(expr, msg)
/* native 2-argument _Static_assert() */
#define wc_static_assert(expr) _Static_assert(expr, #expr)
#ifndef wc_static_assert2
#define wc_static_assert2(expr, msg) _Static_assert(expr, msg)
#endif
#else
#define static_assert(expr) \
struct WC_CPP_CAT(wc_dummy_struct_L, __LINE__)
#ifndef static_assert2
#define static_assert2(expr, msg) static_assert(expr)
/* fallback -- map wc_static_assert*() to do-nothing. */
#define wc_static_assert(expr) struct wc_static_assert_dummy_struct
#ifndef wc_static_assert2
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
#endif
#endif
#elif !defined(static_assert2)
#define static_assert2(expr, msg) static_assert(expr)
#elif !defined(wc_static_assert2)
#define wc_static_assert2(expr, msg) wc_static_assert(expr)
#endif
#ifndef SAVE_VECTOR_REGISTERS