v2-0001-Make-copyObject-work-in-C.patch
text/x-patch
Filename: v2-0001-Make-copyObject-work-in-C.patch
Type: text/x-patch
Part: 0
Message:
Re: Make copyObject work in C++
From 5a076be8b919034c7ff469e39a92d76c78590a59 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <postgres@jeltef.nl> Date: Fri, 5 Dec 2025 15:37:59 +0100 Subject: [PATCH v2 1/2] Make copyObject work in C++ Calling copyObject fails in C++ with an error like in most setups: error: use of undeclared identifier 'typeof'; did you mean 'typeid' This is due to the C compiler supporting used to compile postgres supporting typeof, but that function actually not being present in the C++ compiler. This fixes that by defining pg_exprtype which maps to typeof or decltype depending on the compiler. While pg_typeof would have been a more natural name, that one is already taken in our codebase as the implementation of the pg_typeof UDF. --- src/include/c.h | 13 +++++++++++++ src/include/nodes/nodes.h | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index ccd2b654d45..46a97f11ae7 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -407,6 +407,19 @@ #define unlikely(x) ((x) != 0) #endif +/* + * pg_exprtype + * Get the type of an expression at compile time. + * + * In C++ we use decltype since typeof is not standard C++, while in C we use + * typeof when available. + */ +#if defined(__cplusplus) +#define pg_exprtype(x) decltype(x) +#elif defined(HAVE_TYPEOF) +#define pg_exprtype(x) typeof(x) +#endif + /* * CppAsString * Convert the argument to a string, using the C preprocessor. diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index fb3957e75e5..a8f42431828 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -226,8 +226,8 @@ extern int16 *readAttrNumberCols(int numCols); extern void *copyObjectImpl(const void *from); /* cast result back to argument type, if supported by compiler */ -#ifdef HAVE_TYPEOF -#define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj)) +#ifdef pg_exprtype +#define copyObject(obj) ((pg_exprtype(obj)) copyObjectImpl(obj)) #else #define copyObject(obj) copyObjectImpl(obj) #endif base-commit: 31280d96a64850f5a9a924088890ab43a2905237 -- 2.52.0