From 7d074e7f9329fa87fc8ef722df7095220b665751 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot Date: Mon, 3 Nov 2025 06:33:01 +0000 Subject: [PATCH v4 2/4] Introduce PG_DEPRECATED() and deprecate XLogRecPtrIsInvalid() This commit creates a new macro PG_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 24 (means until the new macro is available on all the supported major versions). --- src/include/access/xlogdefs.h | 14 +++++++++++--- src/include/c.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) 46.3% src/include/access/ 53.6% src/include/ diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h index b16b2a1c8a3..2589a21083b 100644 --- a/src/include/access/xlogdefs.h +++ b/src/include/access/xlogdefs.h @@ -32,10 +32,18 @@ typedef uint64 XLogRecPtr; * New code should use XLogRecPtrIsValid() instead of XLogRecPtrIsInvalid() * for consistency with the affirmative form of other *IsValid() macros and to * avoid awkward double negative. - * This macro is retained for convenience of third-party code but could - * be deprecated in the future. + * This function is retained for convenience of third-party code but is/will be + * deprecated as of version 24. */ -#define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr) +#if PG_VERSION_NUM >= 240000 +PG_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..60e13cd5d6d 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -227,6 +227,21 @@ #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. + */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L || \ +defined(__cplusplus) && __cplusplus >= 201402L +#define PG_DEPRECATED(msg) [[deprecated(msg)]] +#elif defined(__GNUC__) || defined(__clang__) +#define PG_DEPRECATED(msg) __attribute__((deprecated(msg))) +#elif defined(_MSC_VER) +#define PG_DEPRECATED(msg) __declspec(deprecated(msg)) +#else +#define PG_DEPRECATED(msg) +#endif + /* GCC supports format attributes */ #if defined(__GNUC__) #define pg_attribute_format_arg(a) __attribute__((format_arg(a))) -- 2.34.1