On 5/5/22 15:08, Richard Biener wrote: > On Thu, May 5, 2022 at 2:41 PM Martin Liška <mli...@suse.cz> wrote: >> >> On 5/5/22 14:29, Richard Biener wrote: >>> Can we then use static_assert (...) instead and remove the >>> macro? >> >> Oh yes, we can ;) >> >>> Do we have C compiled code left (I think we might, >>> otherwise we'd not have __cplusplus guards in system.h), >>> in which case the #if should change to #ifdef __cplusplus? >> >> No, there's no such a consumer of the macro. > > OK, but for C uses it should still be different so my suggestion > to change to #ifdef __cplusplus remains. OTOH then the change > is somewhat pointless.
Sure, so something like this? Thanks, Martin > >> What about the updated version of the patch? >> >> Cheers, >> Martin
From 100b7a3de69605ab7e80680e6a6e651e31366bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Li=C5=A1ka?= <mli...@suse.cz> Date: Thu, 5 May 2022 14:18:58 +0200 Subject: [PATCH] Simplify STATIC_ASSERT macro. For C++, use always __static_assert and for C, use the negative array index. gcc/ChangeLog: * basic-block.h (STATIC_ASSERT): Use normal STATIC_ASSERT. * system.h (STATIC_ASSERT): Define as static_assert for C++ and fallback to array index in C. --- gcc/basic-block.h | 5 +---- gcc/system.h | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/gcc/basic-block.h b/gcc/basic-block.h index e3fff1f6975..21a9b24dbf9 100644 --- a/gcc/basic-block.h +++ b/gcc/basic-block.h @@ -158,10 +158,7 @@ struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_d /* This ensures that struct gimple_bb_info is smaller than struct rtl_bb_info, so that inlining the former into basic_block_def is the better choice. */ -typedef int __assert_gimple_bb_smaller_rtl_bb - [(int) sizeof (struct rtl_bb_info) - - (int) sizeof (struct gimple_bb_info)]; - +STATIC_ASSERT (sizeof (rtl_bb_info) >= sizeof (gimple_bb_info)); #define BB_FREQ_MAX 10000 diff --git a/gcc/system.h b/gcc/system.h index 1121af485a4..1c783c5331d 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -835,8 +835,7 @@ extern void fancy_abort (const char *, int, const char *) #define STATIC_CONSTANT_P(X) (false && (X)) #endif -/* static_assert (COND, MESSAGE) is available in C++11 onwards. */ -#if __cplusplus >= 201103L +#ifdef __cplusplus #define STATIC_ASSERT(X) \ static_assert ((X), #X) #else -- 2.36.0