From 18e3d334d480a05103d6dde46d511775fd987f84 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 18 Nov 2025 08:43:13 +0100 Subject: [PATCH 6/6] Use static_assert inside StaticAssert* macros For C23 alignment and to unify the C and C++ definitions. --- src/include/c.h | 19 +++++++++---------- src/include/regex/regcustom.h | 1 + 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index d462ebbebd1..e5779ee5c26 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -59,6 +59,7 @@ #include "pg_config_os.h" /* config from include/port/PORTNAME.h */ /* System header files that should be available everywhere in Postgres */ +#include #include #include #include @@ -863,7 +864,6 @@ typedef NameData *Name; #elif defined(FRONTEND) -#include #define Assert(p) assert(p) #define AssertMacro(p) ((void) assert(p)) @@ -914,22 +914,21 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName, * If the "condition" (a compile-time-constant expression) evaluates to false, * throw a compile error using the "errmessage" (a string literal). * - * We require C11 and C++11, so _Static_assert()/static_assert() are expected - * to be there. For portability, we wrap it into StaticAssertDecl(). - * _Static_assert() is a "declaration", and so it must be placed where for - * example a variable declaration would be valid. As long as we compile with + * We require C11 and C++11, so static_assert() is expected to be there. + * StaticAssertDecl() was previously used for portability, but it's now just a + * plain wrapper and doesn't need to be used in new code. static_assert() is + * a "declaration", and so it must be placed where for example a variable + * declaration would be valid. As long as we compile with * -Wno-declaration-after-statement, that also means it cannot be placed after * statements in a function. The macro StaticAssertExpr() makes it safe to * use in an expression. */ -#ifndef __cplusplus #define StaticAssertDecl(condition, errmessage) \ - _Static_assert(condition, errmessage) + static_assert(condition, errmessage) +#ifndef __cplusplus #define StaticAssertExpr(condition, errmessage) \ - ((void) sizeof(struct {_Static_assert(condition, errmessage); char a;})) + ((void) sizeof(struct {static_assert(condition, errmessage); char a;})) #else /* C++ */ -#define StaticAssertDecl(condition, errmessage) \ - static_assert(condition, errmessage) #define StaticAssertExpr(condition, errmessage) \ ({ static_assert(condition, errmessage); }) #endif /* C++ */ diff --git a/src/include/regex/regcustom.h b/src/include/regex/regcustom.h index 1c0e92f168f..4557e7a62c0 100644 --- a/src/include/regex/regcustom.h +++ b/src/include/regex/regcustom.h @@ -53,6 +53,7 @@ #define FREE(p) pfree(VS(p)) #define REALLOC(p,n) repalloc_extended(VS(p),(n), MCXT_ALLOC_NO_OOM) #define INTERRUPT(re) CHECK_FOR_INTERRUPTS() +#undef assert #define assert(x) Assert(x) /* internal character type and related */ -- 2.51.0