Hi, On Fri, Nov 07, 2025 at 05:18:41PM +0000, Dagfinn Ilmari Mannsåker wrote: > Peter Eisentraut <[email protected]> writes: > > > On 07.11.25 16:03, Bertrand Drouvot wrote: > > > >> +#define pg_attribute_deprecated(msg) [[deprecated(msg)]] > >> +#elif defined(__GNUC__) || defined(__clang__) > > > > The __clang__ part is not needed, because clang defines __GNUC__ also. > > Or, to avoid having to know this, how about __has_attribute(deprecated)? >
Thanks for looking at it! I did some research and found that some older GCC versions did support the deprecated attribute (for example GCC 4.5 added support to the extra message, see [1]) but not __has_attribute (introduced in GCC 5, see [2]). So for example here, we'd have a 4.5-4.9 gap. Then to be on the safe side of things I think it's better to not use __has_attribute() for the deprecated attribute. I added a comment in the attached though. [1]: https://gcc.gnu.org/gcc-4.5/changes.html [2]: https://gcc.gnu.org/gcc-5/changes.html Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
>From 750e128f9c6867e37c33051fc00aa672568153f8 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <[email protected]> Date: Fri, 7 Nov 2025 14:18:31 +0000 Subject: [PATCH v9] Introduce pg_attribute_deprecated() and deprecate XLogRecPtrIsInvalid() This commit creates a new macro pg_attribute_deprecated() to mark a declaration as deprecated with a custom message. The compiler will emit a warning when the deprecated entity is used. Then it makes use of this new macro to emit a deprecated message about XLogRecPtrIsInvalid() as of version 21 (no need to be more conservative and wait until version 24 as XLogRecPtrIsValid() has been added in back branches). --- src/include/access/xlogdefs.h | 17 ++++++++++++++++- src/include/c.h | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) 44.7% src/include/access/ 55.2% src/include/ diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h index 5f07e57c832..1ab33ad59c8 100644 --- a/src/include/access/xlogdefs.h +++ b/src/include/access/xlogdefs.h @@ -27,7 +27,22 @@ typedef uint64 XLogRecPtr; */ #define InvalidXLogRecPtr 0 #define XLogRecPtrIsValid(r) ((r) != InvalidXLogRecPtr) -#define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr) + +/* + * New code should use XLogRecPtrIsValid() instead of XLogRecPtrIsInvalid() + * for consistency with the affirmative form of macros used for other datatypes + * and to avoid awkward double negative. + * This function is retained for convenience of third-party code but is/will be + * deprecated as of version 21. + */ +#if PG_VERSION_NUM >= 210000 +pg_attribute_deprecated("use XLogRecPtrIsValid() instead") +#endif +static inline bool +XLogRecPtrIsInvalid(XLogRecPtr ptr) +{ + return ptr == InvalidXLogRecPtr; +} /* * First LSN to use for "fake" LSNs. diff --git a/src/include/c.h b/src/include/c.h index 757dfff4782..22600cbe3a0 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -227,6 +227,22 @@ #define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused() #endif +/* + * Mark a declaration as deprecated with a custom message. The compiler will + * emit a warning when the deprecated entity is used. + * Note: Some older compilers support the attribute but not __has_attribute, + * which may cause this check to fail. Using compiler detection instead. + */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201402L) +#define pg_attribute_deprecated(msg) [[deprecated(msg)]] +#elif defined(__GNUC__) +#define pg_attribute_deprecated(msg) __attribute__((deprecated(msg))) +#elif defined(_MSC_VER) +#define pg_attribute_deprecated(msg) __declspec(deprecated(msg)) +#else +#define pg_attribute_deprecated(msg) +#endif + /* GCC supports format attributes */ #if defined(__GNUC__) #define pg_attribute_format_arg(a) __attribute__((format_arg(a))) -- 2.34.1
