wolfssl/wolfcrypt/types.h: refactor fallback implementation of wc_static_assert() to depend on __COUNTER__, to avoid namespace collisions on unlucky macro invocations with same line numbers.

This commit is contained in:
Daniel Pouzzner
2025-04-08 19:01:44 +00:00
parent 6d299ea943
commit e1ece63942
2 changed files with 13 additions and 7 deletions

View File

@@ -887,6 +887,7 @@ __BIG_ENDIAN__
__BORLANDC__ __BORLANDC__
__CCRX__ __CCRX__
__COMPILER_VER__ __COMPILER_VER__
__COUNTER__
__CYGWIN__ __CYGWIN__
__DATE__ __DATE__
__DCACHE_PRESENT __DCACHE_PRESENT

View File

@@ -1806,8 +1806,8 @@ typedef struct w64wrapper {
#define PRAGMA_DIAG_POP /* null expansion */ #define PRAGMA_DIAG_POP /* null expansion */
#endif #endif
#define WC_CPP_CAT_(a, b) a ## b #define WC_CPP_CAT4_(a, b, c, d) a ## b ## c ## d
#define WC_CPP_CAT(a, b) WC_CPP_CAT_(a, b) #define WC_CPP_CAT4(a, b, c, d) WC_CPP_CAT4_(a, b, c, d)
#if defined(WC_NO_STATIC_ASSERT) #if defined(WC_NO_STATIC_ASSERT)
#define wc_static_assert(expr) struct wc_static_assert_dummy_struct #define wc_static_assert(expr) struct wc_static_assert_dummy_struct
#define wc_static_assert2(expr, msg) wc_static_assert(expr) #define wc_static_assert2(expr, msg) wc_static_assert(expr)
@@ -1844,11 +1844,16 @@ typedef struct w64wrapper {
#define wc_static_assert2(expr, msg) _Static_assert(expr, msg) #define wc_static_assert2(expr, msg) _Static_assert(expr, msg)
#endif #endif
#else #else
/* C89-compatible fallback */ #ifdef __COUNTER__
#define wc_static_assert(expr) \ #define wc_static_assert(expr) \
struct WC_CPP_CAT(wc_static_assert_dummy_struct_L, __LINE__) { \ struct WC_CPP_CAT4(wc_static_assert_dummy_struct_L, \
char t[(expr) ? 1 : -1]; \ __LINE__, _, __COUNTER__) { \
} char t[(expr) ? 1 : -1]; \
}
#else
#define wc_static_assert(expr) \
struct wc_static_assert_dummy_struct
#endif
#ifndef wc_static_assert2 #ifndef wc_static_assert2
#define wc_static_assert2(expr, msg) wc_static_assert(expr) #define wc_static_assert2(expr, msg) wc_static_assert(expr)
#endif #endif