From 80e2527bf8d55cdb33a7dfa33a888f25e9914850 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 28 Dec 2024 11:00:24 +0100 Subject: [PATCH v2 4/4] Support pg_nodiscard on non-GNU compilers that support C23 Support pg_nodiscard on compilers that support C23 attribute syntax. Previously, only GCC-compatible compilers were supported. Also, define pg_noreturn similarly using C23 attribute syntax if the compiler supports C23. This doesn't have much of an effect right now, since all compilers that support C23 surely also support the existing C11-compatible code. But it keeps pg_nodiscard and pg_noreturn consistent. Discussion: https://www.postgresql.org/message-id/flat/pxr5b3z7jmkpenssra5zroxi7qzzp6eswuggokw64axmdixpnk@zbwxuq7gbbcw --- src/include/c.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index d42548cb1c1..a63439c9cf4 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -135,11 +135,11 @@ /* * pg_nodiscard means the compiler should warn if the result of a function - * call is ignored. The name "nodiscard" is chosen in alignment with - * (possibly future) C and C++ standards. For maximum compatibility, use it - * as a function declaration specifier, so it goes before the return type. + * call is ignored. */ -#ifdef __GNUC__ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define pg_nodiscard [[__nodiscard__]] +#elif defined(__GNUC__) #define pg_nodiscard __attribute__((warn_unused_result)) #else #define pg_nodiscard @@ -151,7 +151,9 @@ * uses __attribute__((noreturn)) in headers, which would get confused if * "noreturn" is defined to "_Noreturn", as is done by . */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define pg_noreturn [[__noreturn__]] +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L #define pg_noreturn _Noreturn #elif defined(_MSC_VER) #define pg_noreturn __declspec(noreturn) -- 2.48.1