diff --git a/m-atomic.h b/m-atomic.h index f5b05895..54ceaa7c 100644 --- a/m-atomic.h +++ b/m-atomic.h @@ -332,4 +332,11 @@ M_END_PROTECTED_CODE #endif +// C17 deprecated ATOMIC_VAR_INIT +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L +# define M_ATOMIC_VAR_INIT(x) (x) +#else +# define M_ATOMIC_VAR_INIT(x) ATOMIC_VAR_INIT(x) +#endif + #endif diff --git a/m-i-shared.h b/m-i-shared.h index fcc2af20..f81fa555 100644 --- a/m-i-shared.h +++ b/m-i-shared.h @@ -48,11 +48,11 @@ M_BEGIN_PROTECTED_CODE /* Value of the interface field for static intialization (Uses C99 designated element). */ #define M_ISHARED_PTR_STATIC_DESIGNATED_INIT(name, type) \ - .M_F(name, _cpt) = ATOMIC_VAR_INIT(0) + .M_F(name, _cpt) = M_ATOMIC_VAR_INIT(0) /* Value of the interface field for static intialization (Uses C89 designated element). */ #define M_ISHARED_PTR_STATIC_INIT(name, type) \ - ATOMIC_VAR_INIT(0) + M_ATOMIC_VAR_INIT(0) /* Define the intrusive shared pointer type and its M_INLINE functions. diff --git a/m-thread.h b/m-thread.h index 0a31f135..4a7da750 100644 --- a/m-thread.h +++ b/m-thread.h @@ -681,7 +681,7 @@ typedef struct { } m_once_t[1]; // Initial value for m_once_t -#define M_ONCE_INIT_VALUE { { ATOMIC_VAR_INIT(0) } } +#define M_ONCE_INIT_VALUE { { M_ATOMIC_VAR_INIT(0) } } // Call the function exactly once M_INLINE void m_once_call(m_once_t o, void (*func)(void)) diff --git a/tests/test-mcore.c b/tests/test-mcore.c index 4f6bf7ff..67a537d2 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -887,13 +887,15 @@ static void test_M_CSTR(void) #undef M_USE_CSTR_ALLOC #define M_USE_CSTR_ALLOC 8 // Disable GNUC warning as we want to test this behavior. - // this warning is not supported by CLANG -#if defined (__GNUC__) && __GNUC__ >= 7 && !defined(__clang__) + // this warning is supported by CLANG +#if (defined (__GNUC__) && __GNUC__ >= 7 && !defined(__clang__)) \ + ||(defined(__clang__) && __clang_major__ >= 18) _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wformat-truncation\"") #endif r = strcmp(M_CSTR("Hello %s %c", "World", '!'), "Hello W"); -#if defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__) +#if (defined (__GNUC__) && __GNUC__ >= 7 && !defined(__clang__)) \ + ||(defined(__clang__) && __clang_major__ >= 18) _Pragma("GCC diagnostic pop") #endif assert (r == 0); diff --git a/tests/test-mworker.c b/tests/test-mworker.c index 46d6fab4..b79f1622 100644 --- a/tests/test-mworker.c +++ b/tests/test-mworker.c @@ -31,7 +31,7 @@ static int fib(int n); struct fib2_s { int x, n; }; -atomic_bool resetFunc_called = ATOMIC_VAR_INIT(false); +atomic_bool resetFunc_called = M_ATOMIC_VAR_INIT(false); static void resetFunc(void) { atomic_store(&resetFunc_called, true);