From f5bbc0a7fb21e9a5dd85f73ab10f613b80e2b172 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 22 Dec 2022 20:42:20 +0100 Subject: [PATCH] Implement multiple kind of workarounds for GCC 12 as it produces more false warnings Include missing header in C++ mode --- m-core.h | 10 +++++++++- m-funcobj.h | 4 +++- m-string.h | 3 ++- tests/test-marray.c | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/m-core.h b/m-core.h index eb0b9ad4..7ee97c47 100644 --- a/m-core.h +++ b/m-core.h @@ -181,10 +181,18 @@ #elif defined(__GNUC__) +#if __GNUC__ >= 12 +/* Warnings disabled for GNU C in C mode (Wstringop-overflow produces false warnings) */ +#define M_BEGIN_PROTECTED_CODE \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \ + _Pragma("GCC diagnostic ignored \"-Wstringop-overflow\"") +#else /* Warnings disabled for GNU C in C mode */ #define M_BEGIN_PROTECTED_CODE \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") +#endif #define M_END_PROTECTED_CODE \ _Pragma("GCC diagnostic pop") @@ -2771,7 +2779,7 @@ namespace m_lib { #define M_CSTR(...) \ (m_lib::m_char_array(__VA_ARGS__)).m_get() -#elif defined(__GNUC__) && !defined(M_ADDRESS_SANITIZER) +#elif defined(__GNUC__) && !defined(M_ADDRESS_SANITIZER) && __GNUC__ < 12 /* Return a constant string constructed based on the printf-liked formated string and its arguments. diff --git a/m-funcobj.h b/m-funcobj.h index 5810f619..f523611c 100644 --- a/m-funcobj.h +++ b/m-funcobj.h @@ -310,7 +310,9 @@ ) \ ) \ { \ - struct M_C(name, _s) *self = (struct M_C(name, _s) *)(void*)_self; \ + /* Let's go through an uintptr_t to avoid [broken] aliasing detection by compiler */ \ + uintptr_t __self = (uintptr_t) _self; \ + struct M_C(name, _s) *self = (struct M_C(name, _s) *)(void*)__self; \ (void) self; /* maybe unused */ \ callback_core; \ } \ diff --git a/m-string.h b/m-string.h index 8ea6d6ff..bc8bb5b6 100644 --- a/m-string.h +++ b/m-string.h @@ -1632,7 +1632,8 @@ m_str1ng_utf8_decode(char c, m_str1ng_utf8_state_e *state, const unsigned int type = m_core_clz32((unsigned char)~c) - (unsigned) (sizeof(uint32_t) - 1) * CHAR_BIT; const m_string_unicode_t mask1 = (UINT32_MAX - (m_string_unicode_t)(*state != M_STR1NG_UTF8_STARTING) + 1); const m_string_unicode_t mask2 = (0xFFU >> type); - *unicode = ((*unicode << 6) & mask1) | ((unsigned int) c & mask2); + const m_string_unicode_t c1 = (m_string_unicode_t) c; + *unicode = ((*unicode << 6) & mask1) | (c1 & mask2); *state = (m_str1ng_utf8_state_e) M_STR1NG_UTF8_STATE_TAB[(unsigned int) *state + type]; } diff --git a/tests/test-marray.c b/tests/test-marray.c index a1d714a8..b5000a40 100644 --- a/tests/test-marray.c +++ b/tests/test-marray.c @@ -449,6 +449,8 @@ static void test_double(void) /* For this, we need new placement support */ #include +/* For std::move */ +#include /* Some Simple Oplist for a C++ class (using new placement feature) Some features may not be always available (like comparison or I/O).