pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedMake copyObject work in C++
51+ messages / 7 participants
[nested] [flat]
Commits from this thread:
2026-04-01 c05ad248f9 Enable test_cplusplusext with MSVC
2026-03-31 82a7cbea74 Disable some C++ warnings in MSVC
2026-03-31 4c83f12535 meson: Make room for C++-only warning flags for MSVC
2026-03-26 f8e7ca3285 Make fixed-length list building macros work in C++
2026-03-06 258248d0bd Make unconstify and unvolatize use StaticAssertVariableIsOfTypeMacro
2026-03-06 e2308350c9 Use typeof everywhere instead of compiler specific spellings
2026-02-17 3d28ecb5ac Test List macros in C++ extensions
2026-02-17 451650eaac Test most StaticAssert macros in C++ extensions
2026-02-07 0af05b5dbb Revert "Change copyObject() to use typeof_unqual"
2026-01-21 b4555cb070 Fix for C++ compatibility
2026-01-20 476b35d4e3 tests: Add a test C++ extension module
* Make copyObject work in C++
@ 2025-12-05 14:46 Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 07:57 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 3 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2025-12-05 14:46 UTC (permalink / raw)
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
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 using decltype instead of typeof when
including the header in C++.
Realized because of Thomas' not about how much of our headers should
work in C++, and remembering I hit this specific problem myself.
Another approach would be to force the value of HAVE_TYPEOF to 0 if __cplusplus.
Attachments:
v1-0001-Make-copyObject-work-in-C.patch (application/x-patch, 1.3K) download
From 7ce44917fe789e394193ff20e3b88b2e82f96c20 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 v1] 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 using decltype instead of typeof when
including the header in C++.
---
src/include/nodes/nodes.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index fb3957e75e5..5a4fa8260f2 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -226,7 +226,9 @@ extern int16 *readAttrNumberCols(int numCols);
extern void *copyObjectImpl(const void *from);
/* cast result back to argument type, if supported by compiler */
-#ifdef HAVE_TYPEOF
+#if defined(__cplusplus)
+#define copyObject(obj) ((decltype(obj)) copyObjectImpl(obj))
+#elif defined(HAVE_TYPEOF)
#define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
#else
#define copyObject(obj) copyObjectImpl(obj)
base-commit: 4d936c3fff1ac8dead2cc240ba3da2ed6337257c
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2025-12-07 19:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 08:00 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2025-12-08 08:11 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 2 replies; 51+ messages in thread
From: Tom Lane @ 2025-12-07 19:45 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
Jelte Fennema-Nio <postgres@jeltef.nl> writes:
> 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 using decltype instead of typeof when
> including the header in C++.
Hmm, this only fixes the one use-case. Admittedly we have only one
use-case, but as soon as we have another we'll have a new problem.
How about instead modifying the macro? Maybe something like this
in c.h (untested):
#ifdef __cplusplus
#undef typeof
#define typeof decltype
#define HAVE_TYPEOF 1
#endif
> Another approach would be to force the value of HAVE_TYPEOF to 0 if __cplusplus.
That would be sad, because we'd lose the type checking ability
of copyObject() in C++ code.
BTW, grepping finds a number of random references to __typeof__ and
__typeof, which probably ought to be updated to be just typeof.
regards, tom lane
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-12-08 08:00 ` Peter Eisentraut <peter@eisentraut.org>
2025-12-08 14:51 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2025-12-08 08:00 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 07.12.25 20:45, Tom Lane wrote:
> Hmm, this only fixes the one use-case. Admittedly we have only one
> use-case, but as soon as we have another we'll have a new problem.
> How about instead modifying the macro? Maybe something like this
> in c.h (untested):
>
> #ifdef __cplusplus
> #undef typeof
> #define typeof decltype
> #define HAVE_TYPEOF 1
> #endif
AFAICT, both gcc and clang support typeof in C++ mode as well. So this
kind of renaming could be confusing.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 08:00 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2025-12-08 14:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 15:31 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Tom Lane @ 2025-12-08 14:51 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
Peter Eisentraut <peter@eisentraut.org> writes:
> AFAICT, both gcc and clang support typeof in C++ mode as well. So this
> kind of renaming could be confusing.
Hm, if that's true then we should not have to do anything ...
so why is Jelte reporting a problem?
regards, tom lane
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 08:00 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2025-12-08 14:51 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-12-08 15:31 ` Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2025-12-08 15:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Mon, 8 Dec 2025 at 15:51, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Peter Eisentraut <peter@eisentraut.org> writes:
> > AFAICT, both gcc and clang support typeof in C++ mode as well. So this
> > kind of renaming could be confusing.
>
> Hm, if that's true then we should not have to do anything ...
> so why is Jelte reporting a problem?
Seems it's related to -std=c++17 vs -std=gnu++17. I was compiling my
code with the former, which throws the error in question[1]. Compiling
with the latter works fine[2].
So I guess it depends what we want to require from C++ extensions.
Should we require them to compile with gnu extensions? My opinion on
that would be no.
[1]: https://godbolt.org/z/fz567hs1r
[2]: https://godbolt.org/z/cq1se55bn
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-12-08 08:11 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-14 16:56 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2025-12-08 08:11 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Sun Dec 7, 2025 at 8:45 PM CET, Tom Lane wrote:
> #ifdef __cplusplus
> #undef typeof
> #define typeof decltype
> #define HAVE_TYPEOF 1
> #endif
Went with defining pg_exprtype (pg_typeof already exists). Undefining
typeof seemed a bit heavy-handed. Especially since I think it would be
nice to backport this so C++ extensions can use copyObject directly.
> BTW, grepping finds a number of random references to __typeof__ and
> __typeof, which probably ought to be updated to be just typeof.
Added a follow on patch that starts using pg_exrtype in all those
places.
Attachments: download all (2 files, .tar.gz)
v2-0001-Make-copyObject-work-in-C.patch (text/x-patch, 2.1K) download
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
v2-0002-Use-pg_exprtype-instead-of-__typeof__-or-__typeof.patch (text/x-patch, 3.7K) download
From 62f920e519004d692b14659c5d00546baa6be87c Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v2 2/2] Use pg_exprtype instead of __typeof__ or __typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 16 ++++------------
2 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 46a97f11ae7..230ea2d10af 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -987,10 +987,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define AssertVariableIsOfType(varname, typename) \
- StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertStmt(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \
@@ -1238,11 +1238,11 @@ typedef struct PGAlignedXLogBlock
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index ea340fee657..dac61b13118 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,16 +38,12 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
- (__typeof__((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
-/*
- * If we don't have __builtin_types_compatible_p, assume we might not have
- * __typeof__ either.
- */
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
(void *) ((rp).relptr_off == 0 ? NULL : (base) + (rp).relptr_off - 1))
@@ -72,16 +68,12 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
- AssertVariableIsOfTypeMacro(val, __typeof__((rp).relptr_type)), \
+ AssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
-/*
- * If we don't have __builtin_types_compatible_p, assume we might not have
- * __typeof__ either.
- */
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Re: Make copyObject work in C++ Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 08:11 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2025-12-14 16:56 ` Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2025-12-14 16:56 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Mon Dec 8, 2025 at 9:11 AM CET, Jelte Fennema-Nio wrote:
> Went with defining pg_exprtype (pg_typeof already exists). Undefining
> typeof seemed a bit heavy-handed. Especially since I think it would be
> nice to backport this so C++ extensions can use copyObject directly.
Rebased version of this patchset after conflicts from 315342ffed.
Attachments: download all (2 files, .tar.gz)
v3-0001-Make-copyObject-work-in-C.patch (text/x-patch, 2.1K) download
From 4d4e137b4712b48bf3b7c5a19813c1956a28538e 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 v3 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 d2cdc76644c..040f2ffc32b 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -418,6 +418,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: c5ae07a90a0f3594e5053a26f3c99b041df427d3
--
2.52.0
v3-0002-Use-pg_exprtype-instead-of-typeof.patch (text/x-patch, 3.1K) download
From 8a4b4749aa87dff7e4e40d2eeb21b84f97811738 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v3 2/2] Use pg_exprtype instead of typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 040f2ffc32b..f0800669f09 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -997,10 +997,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define AssertVariableIsOfType(varname, typename) \
- StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertStmt(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \
@@ -1248,11 +1248,11 @@ typedef struct PGAlignedXLogBlock
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index 48e394dba71..dac61b13118 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,10 +38,10 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
- (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
#define relptr_access(base, rp) \
@@ -68,10 +68,10 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
- AssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
+ AssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
#define relptr_store(base, rp, val) \
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2025-12-08 07:57 ` Peter Eisentraut <peter@eisentraut.org>
2025-12-08 08:33 ` Re: Make copyObject work in C++ David Geier <geidav.pg@gmail.com>
2025-12-09 12:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 2 replies; 51+ messages in thread
From: Peter Eisentraut @ 2025-12-08 07:57 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 05.12.25 15:46, Jelte Fennema-Nio wrote:
> 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 using decltype instead of typeof when
> including the header in C++.
>
> Realized because of Thomas' not about how much of our headers should
> work in C++, and remembering I hit this specific problem myself.
>
> Another approach would be to force the value of HAVE_TYPEOF to 0 if __cplusplus.
In the long run, I would like to change copyObject() to use
typeof_unqual instead, because that handles qualifiers more correctly.
(Currently, copyObject() of a const-qualified pointer results in a
const-qualified pointer, which is nonsensical because the reason you
made the copy is that you can modify it.) See attached patch for an
example. Does C++ have something that is semantically similar to that?
Attachments:
0001-Change-copyObject-to-use-typeof_unqual.patch (text/plain, 5.8K) download
From 1e733f16f116be638cbd4f6a359a01541c9a5d24 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 8 Dec 2025 08:33:18 +0100
Subject: [PATCH] Change copyObject() to use typeof_unqual
The new implementation ensures that the result of copyObject() is not
const-qualified when the input is. This was previously incorrect,
since the point of copyObject() is to make a copy to mutate, but
apparently no code ran into it.
---
config/c-compiler.m4 | 25 +++++++++++++++++++++++
configure | 42 ++++++++++++++++++++++++++++++++++++++
configure.ac | 1 +
meson.build | 24 ++++++++++++++++++++++
src/include/nodes/nodes.h | 4 ++--
src/include/pg_config.h.in | 7 +++++++
6 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 236a59e8536..8ee860c9091 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -160,6 +160,31 @@ if test "$pgac_cv_c_typeof" != no; then
fi])# PGAC_C_TYPEOF
+# PGAC_C_TYPEOF_UNQUAL
+# --------------------
+# Check if the C compiler understands typeof_unqual or a variant. Define
+# HAVE_TYPEOF_UNQUAL if so, and define 'typeof_unqual' to the actual key word.
+#
+AC_DEFUN([PGAC_C_TYPEOF_UNQUAL],
+[AC_CACHE_CHECK(for typeof_unqual, pgac_cv_c_typeof_unqual,
+[pgac_cv_c_typeof_unqual=no
+for pgac_kw in typeof_unqual __typeof_unqual__; do
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;])],
+[pgac_cv_c_typeof_unqual=$pgac_kw])
+ test "$pgac_cv_c_typeof_unqual" != no && break
+done])
+if test "$pgac_cv_c_typeof_unqual" != no; then
+ AC_DEFINE(HAVE_TYPEOF_UNQUAL, 1,
+ [Define to 1 if your compiler understands `typeof_unqual' or something similar.])
+ if test "$pgac_cv_c_typeof_unqual" != typeof_unqual; then
+ AC_DEFINE_UNQUOTED(typeof_unqual, $pgac_cv_c_typeof_unqual, [Define to how the compiler spells `typeof_unqual'.])
+ fi
+fi])# PGAC_C_TYPEOF_UNQUAL
+
# PGAC_C_TYPES_COMPATIBLE
# -----------------------
diff --git a/configure b/configure
index 3a0ed11fa8e..af856b20f0b 100755
--- a/configure
+++ b/configure
@@ -14787,6 +14787,48 @@ _ACEOF
fi
fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for typeof_unqual" >&5
+$as_echo_n "checking for typeof_unqual... " >&6; }
+if ${pgac_cv_c_typeof_unqual+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ pgac_cv_c_typeof_unqual=no
+for pgac_kw in typeof_unqual __typeof_unqual__; do
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ pgac_cv_c_typeof_unqual=$pgac_kw
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ test "$pgac_cv_c_typeof_unqual" != no && break
+done
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_c_typeof_unqual" >&5
+$as_echo "$pgac_cv_c_typeof_unqual" >&6; }
+if test "$pgac_cv_c_typeof_unqual" != no; then
+
+$as_echo "#define HAVE_TYPEOF_UNQUAL 1" >>confdefs.h
+
+ if test "$pgac_cv_c_typeof_unqual" != typeof_unqual; then
+
+cat >>confdefs.h <<_ACEOF
+#define typeof_unqual $pgac_cv_c_typeof_unqual
+_ACEOF
+
+ fi
+fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_types_compatible_p" >&5
$as_echo_n "checking for __builtin_types_compatible_p... " >&6; }
if ${pgac_cv__types_compatible+:} false; then :
diff --git a/configure.ac b/configure.ac
index c2413720a18..8eced24beb5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1676,6 +1676,7 @@ AC_C_INLINE
PGAC_PRINTF_ARCHETYPE
PGAC_C_STATIC_ASSERT
PGAC_C_TYPEOF
+PGAC_C_TYPEOF_UNQUAL
PGAC_C_TYPES_COMPATIBLE
PGAC_C_BUILTIN_CONSTANT_P
PGAC_C_BUILTIN_OP_OVERFLOW
diff --git a/meson.build b/meson.build
index 6e7ddd74683..85b98ad81db 100644
--- a/meson.build
+++ b/meson.build
@@ -2818,6 +2818,30 @@ int main(void)
endif
endforeach
+# Check if the C compiler understands typeof_unqual or a variant. Define
+# HAVE_TYPEOF_UNQUAL if so, and define 'typeof_unqual' to the actual key word.
+foreach kw : ['typeof_unqual', '__typeof_unqual__']
+ if cc.compiles('''
+int main(void)
+{
+ int x = 0;
+ @0@(x) y;
+ y = x;
+ return y;
+}
+'''.format(kw),
+ name: kw,
+ args: test_c_args, include_directories: postgres_inc)
+
+ cdata.set('HAVE_TYPEOF_UNQUAL', 1)
+ if kw != 'typeof_unqual'
+ cdata.set('typeof_unqual', kw)
+ endif
+
+ break
+ endif
+endforeach
+
# Even though restrict is in C99 and should be supported by all
# supported compilers, this indirection is useful because __restrict
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index fb3957e75e5..0ac0be1b288 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 HAVE_TYPEOF_UNQUAL
+#define copyObject(obj) ((typeof_unqual(*(obj)) *) copyObjectImpl(obj))
#else
#define copyObject(obj) copyObjectImpl(obj)
#endif
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index b0b0cfdaf79..503467ca092 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -472,6 +472,10 @@
/* Define to 1 if your compiler understands `typeof' or something similar. */
#undef HAVE_TYPEOF
+/* Define to 1 if your compiler understands `typeof_unqual' or something
+ similar. */
+#undef HAVE_TYPEOF_UNQUAL
+
/* Define to 1 if you have the <uchar.h> header file. */
#undef HAVE_UCHAR_H
@@ -815,3 +819,6 @@
/* Define to how the compiler spells `typeof'. */
#undef typeof
+
+/* Define to how the compiler spells `typeof_unqual'. */
+#undef typeof_unqual
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-08 07:57 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2025-12-08 08:33 ` David Geier <geidav.pg@gmail.com>
2025-12-08 08:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 1 reply; 51+ messages in thread
From: David Geier @ 2025-12-08 08:33 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 08.12.2025 08:57, Peter Eisentraut wrote:
> On 05.12.25 15:46, Jelte Fennema-Nio wrote:
>> 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 using decltype instead of typeof when
>> including the header in C++.
>>
>> Realized because of Thomas' not about how much of our headers should
>> work in C++, and remembering I hit this specific problem myself.
>>
>> Another approach would be to force the value of HAVE_TYPEOF to 0 if
>> __cplusplus.
>
> In the long run, I would like to change copyObject() to use
> typeof_unqual instead, because that handles qualifiers more correctly.
> (Currently, copyObject() of a const-qualified pointer results in a
> const-qualified pointer, which is nonsensical because the reason you
> made the copy is that you can modify it.) See attached patch for an
> example. Does C++ have something that is semantically similar to that?
Since C++11 there's std::remove_const which can be used as
std::remove_const<decltype(type)>::type.
I'm not aware of anything pre C++11, except for rolling your own variant
of std::remove_const via template specialization.
--
David Geier
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-08 07:57 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2025-12-08 08:33 ` Re: Make copyObject work in C++ David Geier <geidav.pg@gmail.com>
@ 2025-12-08 08:52 ` Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2025-12-08 08:52 UTC (permalink / raw)
To: David Geier <geidav.pg@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Mon, 8 Dec 2025 at 09:33, David Geier <geidav.pg@gmail.com> wrote:
> Since C++11 there's std::remove_const which can be used as
> std::remove_const<decltype(type)>::type.
>
> I'm not aware of anything pre C++11, except for rolling your own variant
> of std::remove_const via template specialization.
I think depending on C++11 sounds fine, since we're also depending on
C11 and people tend to use much more recent C++ versions than C
versions (so probably we could even require something higher).
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-08 07:57 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2025-12-09 12:58 ` Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2025-12-09 12:58 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Mon, 8 Dec 2025 at 08:57, Peter Eisentraut <peter@eisentraut.org> wrote:
> In the long run, I would like to change copyObject() to use
> typeof_unqual instead, because that handles qualifiers more correctly.
> (Currently, copyObject() of a const-qualified pointer results in a
> const-qualified pointer, which is nonsensical because the reason you
> made the copy is that you can modify it.) See attached patch for an
> example. Does C++ have something that is semantically similar to that?
Yes, there's a std::remove_cv, std::remove_const, and std::remove_volatile[1].
[1]: https://en.cppreference.com/w/cpp/types/remove_cv.html
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2025-12-16 12:28 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2025-12-16 12:28 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 05.12.25 15:46, Jelte Fennema-Nio wrote:
> 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 using decltype instead of typeof when
> including the header in C++.
>
> Realized because of Thomas' not about how much of our headers should
> work in C++, and remembering I hit this specific problem myself.
I think it might be good to create a test extension written in C++, like
under src/test/modules/, and sprinkle it with various constructs like
copyObject() and static assertions, and whatever else we find that is
possibly problematic. Then patches like this one would be much easier
to analyze and test and keep working in the future.
This would probably require resolving
<https://commitfest.postgresql.org/patch/5885/; first.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-03 09:32 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-03 09:32 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Tue Dec 16, 2025 at 1:28 PM CET, Peter Eisentraut wrote:
> I think it might be good to create a test extension written in C++, like
> under src/test/modules/, and sprinkle it with various constructs like
> copyObject() and static assertions, and whatever else we find that is
> possibly problematic.
Attached is a patchset that does that. It required a few more fixes to
make the extension compile on MSVC too.
Attachments: download all (4 files, .tar.gz)
v4-0001-Make-copyObject-work-in-C.patch (text/x-patch, 2.1K) download
From 290a1ab7788756adaed14dc2b483156d65bc3b95 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 v4 1/4] Make copyObject work in C++
Calling copyObject in C++ without GNU extensions fails with an error
like this:
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 name 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 77c754a904a..18bd50da510 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -418,6 +418,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 b6ad28618ab..f5e17e670b7 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: 094b61ce3ebbb1258675cb9b4eca9198628e2177
--
2.52.0
v4-0002-Use-pg_exprtype-instead-of-typeof.patch (text/x-patch, 3.1K) download
From f9693ae786b0859c627098ec9a47f048e55a1fa5 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v4 2/4] Use pg_exprtype instead of typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 18bd50da510..beed3a1a52d 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -976,10 +976,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define AssertVariableIsOfType(varname, typename) \
- StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertStmt(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \
@@ -1227,11 +1227,11 @@ typedef struct PGAlignedXLogBlock
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index aeb17fa24a5..3e03d34d9ad 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,10 +38,10 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
- (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
#define relptr_access(base, rp) \
@@ -68,10 +68,10 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
- AssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
+ AssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
#define relptr_store(base, rp, val) \
--
2.52.0
v4-0003-Revert-Replace-pg_restrict-by-standard-restrict.patch (text/x-patch, 11.3K) download
From cbdc5128717aa0f2c1c0ec3592bdfb0ff09863a2 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 3 Jan 2026 00:43:59 +0100
Subject: [PATCH v4 3/4] Revert "Replace pg_restrict by standard restrict"
This reverts commit f0f2c0c1aef95757c4e7f144d5577e2b0d814279.
It turns out that this completely broke compiling C++ extensions on
MSVC. The restrict replacement with __restrict would break usages of
__decltype(restrict) in standard library headers, resulting in errors
like this:
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\corecrt_malloc.h(58): error C2485: '__restrict': unrecognized extended attribute
---
configure | 18 ++++++++++++++----
configure.ac | 16 ++++++++++++----
meson.build | 13 +++++++------
src/bin/pg_verifybackup/pg_verifybackup.c | 4 ++--
src/bin/pg_verifybackup/pg_verifybackup.h | 4 ++--
src/common/logging.c | 4 ++--
src/common/string.c | 2 +-
src/include/c.h | 6 ------
src/include/common/logging.h | 4 ++--
src/include/common/string.h | 2 +-
src/include/libpq/pqformat.h | 12 ++++++------
src/include/pg_config.h.in | 4 ++++
12 files changed, 53 insertions(+), 36 deletions(-)
diff --git a/configure b/configure
index 78597c6229a..26883131d4c 100755
--- a/configure
+++ b/configure
@@ -15131,10 +15131,10 @@ _ACEOF
fi
-# Even though restrict is in C99 and should be supported by all
-# supported compilers, this test is useful because it will prefer a
-# spelling that also works in C++ (often __restrict). (restrict is
-# not part of the C++ standard.)
+# MSVC doesn't cope well with defining restrict to __restrict, the
+# spelling it understands, because it conflicts with
+# __declspec(restrict). Therefore we define pg_restrict to the
+# appropriate definition, which presumably won't conflict.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
if ${ac_cv_c_restrict+:} false; then :
@@ -15181,6 +15181,16 @@ _ACEOF
;;
esac
+if test "$ac_cv_c_restrict" = "no"; then
+ pg_restrict=""
+else
+ pg_restrict="$ac_cv_c_restrict"
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define pg_restrict $pg_restrict
+_ACEOF
+
ac_fn_c_check_type "$LINENO" "struct option" "ac_cv_type_struct_option" "#ifdef HAVE_GETOPT_H
#include <getopt.h>
diff --git a/configure.ac b/configure.ac
index 2ccf410f94c..08da448c1f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1689,11 +1689,19 @@ PGAC_UNION_SEMUN
AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
PGAC_STRUCT_SOCKADDR_SA_LEN
-# Even though restrict is in C99 and should be supported by all
-# supported compilers, this test is useful because it will prefer a
-# spelling that also works in C++ (often __restrict). (restrict is
-# not part of the C++ standard.)
+# MSVC doesn't cope well with defining restrict to __restrict, the
+# spelling it understands, because it conflicts with
+# __declspec(restrict). Therefore we define pg_restrict to the
+# appropriate definition, which presumably won't conflict.
AC_C_RESTRICT
+if test "$ac_cv_c_restrict" = "no"; then
+ pg_restrict=""
+else
+ pg_restrict="$ac_cv_c_restrict"
+fi
+AC_DEFINE_UNQUOTED([pg_restrict], [$pg_restrict],
+[Define to keyword to use for C99 restrict support, or to nothing if not
+supported])
AC_CHECK_TYPES([struct option], [], [],
[#ifdef HAVE_GETOPT_H
diff --git a/meson.build b/meson.build
index 467f7f005a6..cc3ded782e4 100644
--- a/meson.build
+++ b/meson.build
@@ -2825,12 +2825,13 @@ int main(void)
endforeach
-# Even though restrict is in C99 and should be supported by all
-# supported compilers, this indirection is useful because __restrict
-# also works in C++ in all supported compilers. (If not, then we
-# might have to write a real test.) (restrict is not part of the C++
-# standard.)
-cdata.set('restrict', '__restrict')
+# MSVC doesn't cope well with defining restrict to __restrict, the spelling it
+# understands, because it conflicts with __declspec(restrict). Therefore we
+# define pg_restrict to the appropriate definition, which presumably won't
+# conflict.
+#
+# We assume C99 support, so we don't need to make this conditional.
+cdata.set('pg_restrict', '__restrict')
# Most libraries are included only if they demonstrably provide a function we
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 456e0375e13..f9f2d457f2f 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -1228,7 +1228,7 @@ parse_required_wal(verifier_context *context, char *pg_waldump_path,
* context says we should.
*/
void
-report_backup_error(verifier_context *context, const char *restrict fmt,...)
+report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
{
va_list ap;
@@ -1245,7 +1245,7 @@ report_backup_error(verifier_context *context, const char *restrict fmt,...)
* Report a fatal error and exit
*/
void
-report_fatal_error(const char *restrict fmt,...)
+report_fatal_error(const char *pg_restrict fmt,...)
{
va_list ap;
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.h b/src/bin/pg_verifybackup/pg_verifybackup.h
index 1cd76a8826b..a99d9bfd581 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.h
+++ b/src/bin/pg_verifybackup/pg_verifybackup.h
@@ -96,9 +96,9 @@ typedef struct verifier_context
} verifier_context;
extern void report_backup_error(verifier_context *context,
- const char *restrict fmt,...)
+ const char *pg_restrict fmt,...)
pg_attribute_printf(2, 3);
-pg_noreturn extern void report_fatal_error(const char *restrict fmt,...)
+pg_noreturn extern void report_fatal_error(const char *pg_restrict fmt,...)
pg_attribute_printf(1, 2);
extern bool should_ignore_relpath(verifier_context *context,
const char *relpath);
diff --git a/src/common/logging.c b/src/common/logging.c
index 214a87f2189..5206949e5d8 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -206,7 +206,7 @@ pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno)
void
pg_log_generic(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt,...)
+ const char *pg_restrict fmt,...)
{
va_list ap;
@@ -217,7 +217,7 @@ pg_log_generic(enum pg_log_level level, enum pg_log_part part,
void
pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt, va_list ap)
+ const char *pg_restrict fmt, va_list ap)
{
int save_errno = errno;
const char *filename = NULL;
diff --git a/src/common/string.c b/src/common/string.c
index fff14d3facf..41c74a1502d 100644
--- a/src/common/string.c
+++ b/src/common/string.c
@@ -47,7 +47,7 @@ pg_str_endswith(const char *str, const char *end)
* strtoint --- just like strtol, but returns int not long
*/
int
-strtoint(const char *restrict str, char **restrict endptr, int base)
+strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
{
long val;
diff --git a/src/include/c.h b/src/include/c.h
index beed3a1a52d..df6c753d908 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -108,12 +108,6 @@
#define inline
#endif
-/*
- * Previously used PostgreSQL-specific spelling, for backward compatibility
- * for extensions.
- */
-#define pg_restrict restrict
-
/*
* Attribute macros
*
diff --git a/src/include/common/logging.h b/src/include/common/logging.h
index b5caec0bff1..bccba4ac07b 100644
--- a/src/include/common/logging.h
+++ b/src/include/common/logging.h
@@ -93,10 +93,10 @@ void pg_logging_set_pre_callback(void (*cb) (void));
void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
void pg_log_generic(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt,...)
+ const char *pg_restrict fmt,...)
pg_attribute_printf(3, 4);
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt, va_list ap)
+ const char *pg_restrict fmt, va_list ap)
pg_attribute_printf(3, 0);
/*
diff --git a/src/include/common/string.h b/src/include/common/string.h
index 5e1bd61c710..2a7c31ea74e 100644
--- a/src/include/common/string.h
+++ b/src/include/common/string.h
@@ -25,7 +25,7 @@ typedef struct PromptInterruptContext
/* functions in src/common/string.c */
extern bool pg_str_endswith(const char *str, const char *end);
-extern int strtoint(const char *restrict str, char **restrict endptr,
+extern int strtoint(const char *pg_restrict str, char **pg_restrict endptr,
int base);
extern char *pg_clean_ascii(const char *str, int alloc_flags);
extern int pg_strip_crlf(char *str);
diff --git a/src/include/libpq/pqformat.h b/src/include/libpq/pqformat.h
index 911d9397f5e..bc4ab1381a9 100644
--- a/src/include/libpq/pqformat.h
+++ b/src/include/libpq/pqformat.h
@@ -34,7 +34,7 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
* Append a [u]int8 to a StringInfo buffer, which already has enough space
* preallocated.
*
- * The use of restrict allows the compiler to optimize the code based on
+ * The use of pg_restrict allows the compiler to optimize the code based on
* the assumption that buf, buf->len, buf->data and *buf->data don't
* overlap. Without the annotation buf->len etc cannot be kept in a register
* over subsequent pq_writeintN calls.
@@ -43,7 +43,7 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
* overly picky and demanding a * before a restrict.
*/
static inline void
-pq_writeint8(StringInfoData *restrict buf, uint8 i)
+pq_writeint8(StringInfoData *pg_restrict buf, uint8 i)
{
uint8 ni = i;
@@ -57,7 +57,7 @@ pq_writeint8(StringInfoData *restrict buf, uint8 i)
* preallocated.
*/
static inline void
-pq_writeint16(StringInfoData *restrict buf, uint16 i)
+pq_writeint16(StringInfoData *pg_restrict buf, uint16 i)
{
uint16 ni = pg_hton16(i);
@@ -71,7 +71,7 @@ pq_writeint16(StringInfoData *restrict buf, uint16 i)
* preallocated.
*/
static inline void
-pq_writeint32(StringInfoData *restrict buf, uint32 i)
+pq_writeint32(StringInfoData *pg_restrict buf, uint32 i)
{
uint32 ni = pg_hton32(i);
@@ -85,7 +85,7 @@ pq_writeint32(StringInfoData *restrict buf, uint32 i)
* preallocated.
*/
static inline void
-pq_writeint64(StringInfoData *restrict buf, uint64 i)
+pq_writeint64(StringInfoData *pg_restrict buf, uint64 i)
{
uint64 ni = pg_hton64(i);
@@ -105,7 +105,7 @@ pq_writeint64(StringInfoData *restrict buf, uint64 i)
* sent to the frontend.
*/
static inline void
-pq_writestring(StringInfoData *restrict buf, const char *restrict str)
+pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
{
int slen = strlen(str);
char *p;
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index f0091b09cbe..bc68a815e15 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -799,6 +799,10 @@
#undef inline
#endif
+/* Define to keyword to use for C99 restrict support, or to nothing if not
+ supported */
+#undef pg_restrict
+
/* Define to the equivalent of the C99 'restrict' keyword, or to
nothing if this is not supported. Do not define if restrict is
supported directly. */
--
2.52.0
v4-0004-tests-Add-a-test-C-extension-module.patch (text/x-patch, 10.6K) download
From d58a560966d53640af8f7f24882ba004221f35ef Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Fri, 2 Jan 2026 22:31:05 +0100
Subject: [PATCH v4 4/4] tests: Add a test C++ extension module
While we already test that our headers are valid C++ using headerscheck,
it turns out that the macros we define might still expand to invalid
C++ code. This adds a small test extension that is compiled using C++
which uses a few macros that have caused problems in the passed or we
expect might cause problems in the future. This is definitely not meant
to be exhaustive. It's main purpose is to serve as a regression test for
previous failures, and as a place where future failures can easily be
added.
To get CI green, this also fixes a few issues when compiling C++
extensions on MSVC. Notably, our use of designated initializers in
common macros means that on MSVC we essentially need C++20. Given that
no-one has complained about that yet, it seems unlikely that anyone is
currently compiling C++ extensions on MSVC with a lower standard. GCC
and clang allow such initializers in earlier standards in also, even
though they only became an official part of C++20.
---
.cirrus.tasks.yml | 6 ++-
meson.build | 4 ++
src/include/c.h | 18 ++++++-
src/include/nodes/pg_list.h | 8 +--
src/test/modules/Makefile | 1 +
src/test/modules/meson.build | 1 +
src/test/modules/test_cplusplusext/Makefile | 24 +++++++++
.../modules/test_cplusplusext/meson.build | 35 +++++++++++++
.../test_cplusplusext/test_cplusplusext.cpp | 51 +++++++++++++++++++
9 files changed, 140 insertions(+), 8 deletions(-)
create mode 100644 src/test/modules/test_cplusplusext/Makefile
create mode 100644 src/test/modules/test_cplusplusext/meson.build
create mode 100644 src/test/modules/test_cplusplusext/test_cplusplusext.cpp
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 038d043d00e..94abf63265c 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -453,7 +453,8 @@ task:
# SANITIZER_FLAGS is set in the tasks below
CFLAGS: -Og -ggdb -fno-sanitize-recover=all $SANITIZER_FLAGS
- CXXFLAGS: $CFLAGS
+ # Use -std=c++11 (not gnu++11) to catch C++ portability issues
+ CXXFLAGS: $CFLAGS -std=c++11
LDFLAGS: $SANITIZER_FLAGS
CC: ccache gcc
CXX: ccache g++
@@ -573,6 +574,7 @@ task:
su postgres <<-EOF
set -e
export CC='ccache gcc -m32'
+ export CXX='ccache g++ -m32'
meson setup \
${MESON_COMMON_PG_CONFIG_ARGS} \
--buildtype=debug \
@@ -806,7 +808,7 @@ task:
configure_script: |
vcvarsall x64
- meson setup --backend ninja %MESON_COMMON_PG_CONFIG_ARGS% --buildtype debug -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% %MESON_FEATURES% build
+ meson setup --backend ninja %MESON_COMMON_PG_CONFIG_ARGS% --buildtype debug -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -Dcpp_args=/std:c++20 %MESON_FEATURES% build
build_script: |
vcvarsall x64
diff --git a/meson.build b/meson.build
index cc3ded782e4..4a63904870e 100644
--- a/meson.build
+++ b/meson.build
@@ -2185,6 +2185,10 @@ if cc.get_id() == 'msvc'
'/w24777', # 'function' : format string 'string' requires an argument of type 'type1', but variadic argument number has type 'type2' [like -Wformat]
]
+ cxxflags_warn += [
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union
+ ]
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
diff --git a/src/include/c.h b/src/include/c.h
index df6c753d908..cc35530424e 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -341,6 +341,16 @@
#define pg_unreachable() abort()
#endif
+/*
+ * C++ has sligthly different syntax for inline compound literals than C. GCC
+ * and Clang support he C-style syntax too, but MSVC does not.
+ */
+#ifdef __cplusplus
+#define pg_compound_literal(type, ...) (type { __VA_ARGS__ })
+#else
+#define pg_compound_literal(type, ...) ((type) { __VA_ARGS__ })
+#endif
+
/*
* Define a compiler-independent macro for determining if an expression is a
* compile-time integer const. We don't define this macro to return 0 when
@@ -948,13 +958,17 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
static_assert(condition, errmessage)
#define StaticAssertStmt(condition, errmessage) \
do { static_assert(condition, errmessage); } while(0)
-#ifdef HAVE_STATEMENT_EXPRESSIONS
+#ifdef __cplusplus
+/* C++11 lambdas provide a convenient way to use static_assert as an expression */
+#define StaticAssertExpr(condition, errmessage) \
+ ((void) ([](){ static_assert(condition, errmessage); }(), 0))
+#elif defined(HAVE_STATEMENT_EXPRESSIONS)
#define StaticAssertExpr(condition, errmessage) \
((void) ({ static_assert(condition, errmessage); true; }))
#else
#define StaticAssertExpr(condition, errmessage) \
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
-#endif /* HAVE_STATEMENT_EXPRESSIONS */
+#endif
/*
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..5498d09bcba 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -204,10 +204,10 @@ list_length(const List *l)
/*
* Convenience macros for building fixed-length lists
*/
-#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
+#define list_make_ptr_cell(v) pg_compound_literal(ListCell, .ptr_value = (v))
+#define list_make_int_cell(v) pg_compound_literal(ListCell, .int_value = (v))
+#define list_make_oid_cell(v) pg_compound_literal(ListCell, .oid_value = (v))
+#define list_make_xid_cell(v) pg_compound_literal(ListCell, .xid_value = (v))
#define list_make1(x1) \
list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile
index 4c6d56d97d8..92ac0a342b5 100644
--- a/src/test/modules/Makefile
+++ b/src/test/modules/Makefile
@@ -20,6 +20,7 @@ SUBDIRS = \
test_bitmapset \
test_bloomfilter \
test_cloexec \
+ test_cplusplusext \
test_copy_callbacks \
test_custom_rmgrs \
test_custom_stats \
diff --git a/src/test/modules/meson.build b/src/test/modules/meson.build
index 1b31c5b98d6..0c7e8ad4856 100644
--- a/src/test/modules/meson.build
+++ b/src/test/modules/meson.build
@@ -19,6 +19,7 @@ subdir('test_aio')
subdir('test_binaryheap')
subdir('test_bitmapset')
subdir('test_bloomfilter')
+subdir('test_cplusplusext')
subdir('test_cloexec')
subdir('test_copy_callbacks')
subdir('test_custom_rmgrs')
diff --git a/src/test/modules/test_cplusplusext/Makefile b/src/test/modules/test_cplusplusext/Makefile
new file mode 100644
index 00000000000..19abd0f98c6
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/Makefile
@@ -0,0 +1,24 @@
+# src/test/modules/test_cplusplusext/Makefile
+#
+# Test that PostgreSQL headers compile with a C++ compiler.
+# If this module compiles, the test passes.
+
+MODULE_big = test_cplusplusext
+OBJS = \
+ $(WIN32RES) \
+ test_cplusplusext.o
+PGFILEDESC = "test_cplusplusext - test C++ compatibility of PostgreSQL headers"
+
+# Use C++ compiler for linking because this module includes C++ files
+override COMPILER = $(CXX) $(CXXFLAGS)
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = src/test/modules/test_cplusplusext
+top_builddir = ../../../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
new file mode 100644
index 00000000000..d47fbfa7f51
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -0,0 +1,35 @@
+# Copyright (c) 2025-2026, PostgreSQL Global Development Group
+
+# This module tests that PostgreSQL headers compile with a C++ compiler.
+# It has no runtime tests - if it compiles, the test passes.
+
+if not add_languages('cpp', required: false, native: false)
+ subdir_done()
+endif
+
+cpp = meson.get_compiler('cpp')
+
+# MSVC requires C++20 for designated initializers used in PG_MODULE_MAGIC and
+# other macros. Skip if the compiler doesn't support them.
+if not cpp.compiles('''
+ struct Foo { int a; int b; };
+ Foo f = {.a = 1, .b = 2};
+ ''',
+ name: 'C++ designated initializers')
+ subdir_done()
+endif
+
+test_cplusplusext_sources = files(
+ 'test_cplusplusext.cpp',
+)
+
+if host_system == 'windows'
+ test_cplusplusext_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
+ '--NAME', 'test_cplusplusext',
+ '--FILEDESC', 'test_cplusplusext - test C++ compatibility of PostgreSQL headers',])
+endif
+
+test_cplusplusext = shared_module('test_cplusplusext',
+ test_cplusplusext_sources,
+ kwargs: pg_test_mod_args,
+)
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
new file mode 100644
index 00000000000..012db8b7959
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -0,0 +1,51 @@
+/*--------------------------------------------------------------------------
+ *
+ * test_cplusplusext.cpp
+ * Test that PostgreSQL headers compile with a C++ compiler.
+ *
+ * This file is compiled with a C++ compiler to verify that PostgreSQL
+ * headers remain compatible with C++ extensions.
+ *
+ * Copyright (c) 2025-2026, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+ *
+ * -------------------------------------------------------------------------
+ */
+
+extern "C" {
+#include "postgres.h"
+#include "fmgr.h"
+#include "nodes/pg_list.h"
+#include "nodes/parsenodes.h"
+
+PG_MODULE_MAGIC;
+
+PG_FUNCTION_INFO_V1(test_cplusplus_compat);
+}
+
+StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
+
+extern "C" Datum
+test_cplusplus_compat(PG_FUNCTION_ARGS)
+{
+ List *node_list = list_make1(makeNode(RangeTblRef));
+ RangeTblRef *copy = copyObject(linitial_node(RangeTblRef, node_list));
+
+ foreach_ptr(RangeTblRef, rtr, node_list) {
+ rtr->rtindex++;
+ }
+
+ foreach_node(RangeTblRef, rtr, node_list) {
+ rtr->rtindex++;
+ }
+
+ StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
+ (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+
+ pfree(copy);
+ list_free_deep(node_list);
+
+ PG_RETURN_VOID();
+}
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-01-10 11:09 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-10 11:09 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Sat Jan 3, 2026 at 10:32 AM CET, Jelte Fennema-Nio wrote:
> Attached is a patchset that does that. It required a few more fixes to
> make the extension compile on MSVC too.
Rebased after Peter merged the C++ improvements from the other thread.
Attachments: download all (4 files, .tar.gz)
v5-0001-Make-copyObject-work-in-C.patch (text/x-patch, 2.1K) download
From b46b6d54553e008db803bbc3ceeac4892eab099c 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 v5 1/4] Make copyObject work in C++
Calling copyObject in C++ without GNU extensions fails with an error
like this:
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 name 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 335af3352d1..b17cc1203b1 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -418,6 +418,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 b6ad28618ab..f5e17e670b7 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: e5a5e0a90750d665cab417322b9f85c806430d85
--
2.52.0
v5-0002-Use-pg_exprtype-instead-of-typeof.patch (text/x-patch, 3.1K) download
From 740895e8b8fb67e2418d9cceb407baa8056814b8 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v5 2/4] Use pg_exprtype instead of typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index b17cc1203b1..39105671e6c 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -984,10 +984,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define AssertVariableIsOfType(varname, typename) \
- StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertStmt(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \
@@ -1235,11 +1235,11 @@ typedef struct PGAlignedXLogBlock
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index aeb17fa24a5..3e03d34d9ad 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,10 +38,10 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
- (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
#define relptr_access(base, rp) \
@@ -68,10 +68,10 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
- AssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
+ AssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
#define relptr_store(base, rp, val) \
--
2.52.0
v5-0003-Revert-Replace-pg_restrict-by-standard-restrict.patch (text/x-patch, 11.3K) download
From 5fbc7dc89d309f7094a81e77703ec0b5339be7f7 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 3 Jan 2026 00:43:59 +0100
Subject: [PATCH v5 3/4] Revert "Replace pg_restrict by standard restrict"
This reverts commit f0f2c0c1aef95757c4e7f144d5577e2b0d814279.
It turns out that this completely broke compiling C++ extensions on
MSVC. The restrict replacement with __restrict would break usages of
__decltype(restrict) in standard library headers, resulting in errors
like this:
C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\corecrt_malloc.h(58): error C2485: '__restrict': unrecognized extended attribute
---
configure | 18 ++++++++++++++----
configure.ac | 16 ++++++++++++----
meson.build | 13 +++++++------
src/bin/pg_verifybackup/pg_verifybackup.c | 4 ++--
src/bin/pg_verifybackup/pg_verifybackup.h | 4 ++--
src/common/logging.c | 4 ++--
src/common/string.c | 2 +-
src/include/c.h | 6 ------
src/include/common/logging.h | 4 ++--
src/include/common/string.h | 2 +-
src/include/libpq/pqformat.h | 12 ++++++------
src/include/pg_config.h.in | 4 ++++
12 files changed, 53 insertions(+), 36 deletions(-)
diff --git a/configure b/configure
index 045c913865d..575f4f05245 100755
--- a/configure
+++ b/configure
@@ -15131,10 +15131,10 @@ _ACEOF
fi
-# Even though restrict is in C99 and should be supported by all
-# supported compilers, this test is useful because it will prefer a
-# spelling that also works in C++ (often __restrict). (restrict is
-# not part of the C++ standard.)
+# MSVC doesn't cope well with defining restrict to __restrict, the
+# spelling it understands, because it conflicts with
+# __declspec(restrict). Therefore we define pg_restrict to the
+# appropriate definition, which presumably won't conflict.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
if ${ac_cv_c_restrict+:} false; then :
@@ -15181,6 +15181,16 @@ _ACEOF
;;
esac
+if test "$ac_cv_c_restrict" = "no"; then
+ pg_restrict=""
+else
+ pg_restrict="$ac_cv_c_restrict"
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define pg_restrict $pg_restrict
+_ACEOF
+
ac_fn_c_check_type "$LINENO" "struct option" "ac_cv_type_struct_option" "#ifdef HAVE_GETOPT_H
#include <getopt.h>
diff --git a/configure.ac b/configure.ac
index 145197e6bd6..c77c2639ec1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1687,11 +1687,19 @@ PGAC_UNION_SEMUN
AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
PGAC_STRUCT_SOCKADDR_SA_LEN
-# Even though restrict is in C99 and should be supported by all
-# supported compilers, this test is useful because it will prefer a
-# spelling that also works in C++ (often __restrict). (restrict is
-# not part of the C++ standard.)
+# MSVC doesn't cope well with defining restrict to __restrict, the
+# spelling it understands, because it conflicts with
+# __declspec(restrict). Therefore we define pg_restrict to the
+# appropriate definition, which presumably won't conflict.
AC_C_RESTRICT
+if test "$ac_cv_c_restrict" = "no"; then
+ pg_restrict=""
+else
+ pg_restrict="$ac_cv_c_restrict"
+fi
+AC_DEFINE_UNQUOTED([pg_restrict], [$pg_restrict],
+[Define to keyword to use for C99 restrict support, or to nothing if not
+supported])
AC_CHECK_TYPES([struct option], [], [],
[#ifdef HAVE_GETOPT_H
diff --git a/meson.build b/meson.build
index 555c94796c6..55df1dd3797 100644
--- a/meson.build
+++ b/meson.build
@@ -2833,12 +2833,13 @@ int main(void)
endforeach
-# Even though restrict is in C99 and should be supported by all
-# supported compilers, this indirection is useful because __restrict
-# also works in C++ in all supported compilers. (If not, then we
-# might have to write a real test.) (restrict is not part of the C++
-# standard.)
-cdata.set('restrict', '__restrict')
+# MSVC doesn't cope well with defining restrict to __restrict, the spelling it
+# understands, because it conflicts with __declspec(restrict). Therefore we
+# define pg_restrict to the appropriate definition, which presumably won't
+# conflict.
+#
+# We assume C99 support, so we don't need to make this conditional.
+cdata.set('pg_restrict', '__restrict')
# Most libraries are included only if they demonstrably provide a function we
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 456e0375e13..f9f2d457f2f 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -1228,7 +1228,7 @@ parse_required_wal(verifier_context *context, char *pg_waldump_path,
* context says we should.
*/
void
-report_backup_error(verifier_context *context, const char *restrict fmt,...)
+report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
{
va_list ap;
@@ -1245,7 +1245,7 @@ report_backup_error(verifier_context *context, const char *restrict fmt,...)
* Report a fatal error and exit
*/
void
-report_fatal_error(const char *restrict fmt,...)
+report_fatal_error(const char *pg_restrict fmt,...)
{
va_list ap;
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.h b/src/bin/pg_verifybackup/pg_verifybackup.h
index 1cd76a8826b..a99d9bfd581 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.h
+++ b/src/bin/pg_verifybackup/pg_verifybackup.h
@@ -96,9 +96,9 @@ typedef struct verifier_context
} verifier_context;
extern void report_backup_error(verifier_context *context,
- const char *restrict fmt,...)
+ const char *pg_restrict fmt,...)
pg_attribute_printf(2, 3);
-pg_noreturn extern void report_fatal_error(const char *restrict fmt,...)
+pg_noreturn extern void report_fatal_error(const char *pg_restrict fmt,...)
pg_attribute_printf(1, 2);
extern bool should_ignore_relpath(verifier_context *context,
const char *relpath);
diff --git a/src/common/logging.c b/src/common/logging.c
index 214a87f2189..5206949e5d8 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -206,7 +206,7 @@ pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno)
void
pg_log_generic(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt,...)
+ const char *pg_restrict fmt,...)
{
va_list ap;
@@ -217,7 +217,7 @@ pg_log_generic(enum pg_log_level level, enum pg_log_part part,
void
pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt, va_list ap)
+ const char *pg_restrict fmt, va_list ap)
{
int save_errno = errno;
const char *filename = NULL;
diff --git a/src/common/string.c b/src/common/string.c
index fff14d3facf..41c74a1502d 100644
--- a/src/common/string.c
+++ b/src/common/string.c
@@ -47,7 +47,7 @@ pg_str_endswith(const char *str, const char *end)
* strtoint --- just like strtol, but returns int not long
*/
int
-strtoint(const char *restrict str, char **restrict endptr, int base)
+strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
{
long val;
diff --git a/src/include/c.h b/src/include/c.h
index 39105671e6c..65173b9d9fd 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -108,12 +108,6 @@
#define inline
#endif
-/*
- * Previously used PostgreSQL-specific spelling, for backward compatibility
- * for extensions.
- */
-#define pg_restrict restrict
-
/*
* Attribute macros
*
diff --git a/src/include/common/logging.h b/src/include/common/logging.h
index b5caec0bff1..bccba4ac07b 100644
--- a/src/include/common/logging.h
+++ b/src/include/common/logging.h
@@ -93,10 +93,10 @@ void pg_logging_set_pre_callback(void (*cb) (void));
void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
void pg_log_generic(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt,...)
+ const char *pg_restrict fmt,...)
pg_attribute_printf(3, 4);
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
- const char *restrict fmt, va_list ap)
+ const char *pg_restrict fmt, va_list ap)
pg_attribute_printf(3, 0);
/*
diff --git a/src/include/common/string.h b/src/include/common/string.h
index 5e1bd61c710..2a7c31ea74e 100644
--- a/src/include/common/string.h
+++ b/src/include/common/string.h
@@ -25,7 +25,7 @@ typedef struct PromptInterruptContext
/* functions in src/common/string.c */
extern bool pg_str_endswith(const char *str, const char *end);
-extern int strtoint(const char *restrict str, char **restrict endptr,
+extern int strtoint(const char *pg_restrict str, char **pg_restrict endptr,
int base);
extern char *pg_clean_ascii(const char *str, int alloc_flags);
extern int pg_strip_crlf(char *str);
diff --git a/src/include/libpq/pqformat.h b/src/include/libpq/pqformat.h
index 911d9397f5e..bc4ab1381a9 100644
--- a/src/include/libpq/pqformat.h
+++ b/src/include/libpq/pqformat.h
@@ -34,7 +34,7 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
* Append a [u]int8 to a StringInfo buffer, which already has enough space
* preallocated.
*
- * The use of restrict allows the compiler to optimize the code based on
+ * The use of pg_restrict allows the compiler to optimize the code based on
* the assumption that buf, buf->len, buf->data and *buf->data don't
* overlap. Without the annotation buf->len etc cannot be kept in a register
* over subsequent pq_writeintN calls.
@@ -43,7 +43,7 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
* overly picky and demanding a * before a restrict.
*/
static inline void
-pq_writeint8(StringInfoData *restrict buf, uint8 i)
+pq_writeint8(StringInfoData *pg_restrict buf, uint8 i)
{
uint8 ni = i;
@@ -57,7 +57,7 @@ pq_writeint8(StringInfoData *restrict buf, uint8 i)
* preallocated.
*/
static inline void
-pq_writeint16(StringInfoData *restrict buf, uint16 i)
+pq_writeint16(StringInfoData *pg_restrict buf, uint16 i)
{
uint16 ni = pg_hton16(i);
@@ -71,7 +71,7 @@ pq_writeint16(StringInfoData *restrict buf, uint16 i)
* preallocated.
*/
static inline void
-pq_writeint32(StringInfoData *restrict buf, uint32 i)
+pq_writeint32(StringInfoData *pg_restrict buf, uint32 i)
{
uint32 ni = pg_hton32(i);
@@ -85,7 +85,7 @@ pq_writeint32(StringInfoData *restrict buf, uint32 i)
* preallocated.
*/
static inline void
-pq_writeint64(StringInfoData *restrict buf, uint64 i)
+pq_writeint64(StringInfoData *pg_restrict buf, uint64 i)
{
uint64 ni = pg_hton64(i);
@@ -105,7 +105,7 @@ pq_writeint64(StringInfoData *restrict buf, uint64 i)
* sent to the frontend.
*/
static inline void
-pq_writestring(StringInfoData *restrict buf, const char *restrict str)
+pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
{
int slen = strlen(str);
char *p;
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 10fa85e78c2..339268dc8ef 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -786,6 +786,10 @@
#undef inline
#endif
+/* Define to keyword to use for C99 restrict support, or to nothing if not
+ supported */
+#undef pg_restrict
+
/* Define to the equivalent of the C99 'restrict' keyword, or to
nothing if this is not supported. Do not define if restrict is
supported directly. */
--
2.52.0
v5-0004-tests-Add-a-test-C-extension-module.patch (text/x-patch, 10.6K) download
From f0d4b25e67555cd7f43cb17ab7bcff870bfea669 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Fri, 2 Jan 2026 22:31:05 +0100
Subject: [PATCH v5 4/4] tests: Add a test C++ extension module
While we already test that our headers are valid C++ using headerscheck,
it turns out that the macros we define might still expand to invalid
C++ code. This adds a small test extension that is compiled using C++
which uses a few macros that have caused problems in the passed or we
expect might cause problems in the future. This is definitely not meant
to be exhaustive. It's main purpose is to serve as a regression test for
previous failures, and as a place where future failures can easily be
added.
To get CI green, this also fixes a few issues when compiling C++
extensions on MSVC. Notably, our use of designated initializers in
common macros means that on MSVC we essentially need C++20. Given that
no-one has complained about that yet, it seems unlikely that anyone is
currently compiling C++ extensions on MSVC with a lower standard. GCC
and clang allow such initializers when compiling for older C++
standards, even though they only became an official part of C++20.
---
.cirrus.tasks.yml | 7 ++-
meson.build | 4 ++
src/include/c.h | 18 ++++++-
src/include/nodes/pg_list.h | 8 +--
src/test/modules/Makefile | 1 +
src/test/modules/meson.build | 1 +
src/test/modules/test_cplusplusext/Makefile | 24 +++++++++
.../modules/test_cplusplusext/meson.build | 35 +++++++++++++
.../test_cplusplusext/test_cplusplusext.cpp | 51 +++++++++++++++++++
9 files changed, 141 insertions(+), 8 deletions(-)
create mode 100644 src/test/modules/test_cplusplusext/Makefile
create mode 100644 src/test/modules/test_cplusplusext/meson.build
create mode 100644 src/test/modules/test_cplusplusext/test_cplusplusext.cpp
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 2a821593ce5..c4b4d213b68 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -450,7 +450,8 @@ task:
# SANITIZER_FLAGS is set in the tasks below
CFLAGS: -Og -ggdb -fno-sanitize-recover=all $SANITIZER_FLAGS
- CXXFLAGS: $CFLAGS
+ # Use -std=c++11 (not gnu++11) to catch C++ portability issues
+ CXXFLAGS: $CFLAGS -std=c++11
LDFLAGS: $SANITIZER_FLAGS
CC: ccache gcc
CXX: ccache g++
@@ -802,9 +803,11 @@ task:
echo 127.0.0.3 pg-loadbalancetest >> c:\Windows\System32\Drivers\etc\hosts
type c:\Windows\System32\Drivers\etc\hosts
+ # Uses C++20 standard, because that's needed for MSVC to accept designated
+ # initializers.
configure_script: |
vcvarsall x64
- meson setup --backend ninja %MESON_COMMON_PG_CONFIG_ARGS% --buildtype debug -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% %MESON_FEATURES% build
+ meson setup --backend ninja %MESON_COMMON_PG_CONFIG_ARGS% --buildtype debug -Db_pch=true -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=%TAR% -Dcpp_args=/std:c++20 %MESON_FEATURES% build
build_script: |
vcvarsall x64
diff --git a/meson.build b/meson.build
index 55df1dd3797..63d725dfc9d 100644
--- a/meson.build
+++ b/meson.build
@@ -2192,6 +2192,10 @@ if cc.get_id() == 'msvc'
'/w24777', # 'function' : format string 'string' requires an argument of type 'type1', but variadic argument number has type 'type2' [like -Wformat]
]
+ cxxflags_warn += [
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union
+ ]
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
diff --git a/src/include/c.h b/src/include/c.h
index 65173b9d9fd..d2f354e7e15 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -341,6 +341,16 @@
#define pg_unreachable() abort()
#endif
+/*
+ * C++ has sligthly different syntax for inline compound literals than C. GCC
+ * and Clang support he C-style syntax too, but MSVC does not.
+ */
+#ifdef __cplusplus
+#define pg_compound_literal(type, ...) (type { __VA_ARGS__ })
+#else
+#define pg_compound_literal(type, ...) ((type) { __VA_ARGS__ })
+#endif
+
/*
* Define a compiler-independent macro for determining if an expression is a
* compile-time integer const. We don't define this macro to return 0 when
@@ -956,13 +966,17 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
static_assert(condition, errmessage)
#define StaticAssertStmt(condition, errmessage) \
do { static_assert(condition, errmessage); } while(0)
-#ifdef HAVE_STATEMENT_EXPRESSIONS
+#ifdef __cplusplus
+/* C++11 lambdas provide a convenient way to use static_assert as an expression */
+#define StaticAssertExpr(condition, errmessage) \
+ ((void) ([](){ static_assert(condition, errmessage); }(), 0))
+#elif defined(HAVE_STATEMENT_EXPRESSIONS)
#define StaticAssertExpr(condition, errmessage) \
((void) ({ static_assert(condition, errmessage); true; }))
#else
#define StaticAssertExpr(condition, errmessage) \
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
-#endif /* HAVE_STATEMENT_EXPRESSIONS */
+#endif
/*
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..5498d09bcba 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -204,10 +204,10 @@ list_length(const List *l)
/*
* Convenience macros for building fixed-length lists
*/
-#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
+#define list_make_ptr_cell(v) pg_compound_literal(ListCell, .ptr_value = (v))
+#define list_make_int_cell(v) pg_compound_literal(ListCell, .int_value = (v))
+#define list_make_oid_cell(v) pg_compound_literal(ListCell, .oid_value = (v))
+#define list_make_xid_cell(v) pg_compound_literal(ListCell, .xid_value = (v))
#define list_make1(x1) \
list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile
index 4c6d56d97d8..92ac0a342b5 100644
--- a/src/test/modules/Makefile
+++ b/src/test/modules/Makefile
@@ -20,6 +20,7 @@ SUBDIRS = \
test_bitmapset \
test_bloomfilter \
test_cloexec \
+ test_cplusplusext \
test_copy_callbacks \
test_custom_rmgrs \
test_custom_stats \
diff --git a/src/test/modules/meson.build b/src/test/modules/meson.build
index 1b31c5b98d6..0c7e8ad4856 100644
--- a/src/test/modules/meson.build
+++ b/src/test/modules/meson.build
@@ -19,6 +19,7 @@ subdir('test_aio')
subdir('test_binaryheap')
subdir('test_bitmapset')
subdir('test_bloomfilter')
+subdir('test_cplusplusext')
subdir('test_cloexec')
subdir('test_copy_callbacks')
subdir('test_custom_rmgrs')
diff --git a/src/test/modules/test_cplusplusext/Makefile b/src/test/modules/test_cplusplusext/Makefile
new file mode 100644
index 00000000000..19abd0f98c6
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/Makefile
@@ -0,0 +1,24 @@
+# src/test/modules/test_cplusplusext/Makefile
+#
+# Test that PostgreSQL headers compile with a C++ compiler.
+# If this module compiles, the test passes.
+
+MODULE_big = test_cplusplusext
+OBJS = \
+ $(WIN32RES) \
+ test_cplusplusext.o
+PGFILEDESC = "test_cplusplusext - test C++ compatibility of PostgreSQL headers"
+
+# Use C++ compiler for linking because this module includes C++ files
+override COMPILER = $(CXX) $(CXXFLAGS)
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = src/test/modules/test_cplusplusext
+top_builddir = ../../../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
new file mode 100644
index 00000000000..d47fbfa7f51
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -0,0 +1,35 @@
+# Copyright (c) 2025-2026, PostgreSQL Global Development Group
+
+# This module tests that PostgreSQL headers compile with a C++ compiler.
+# It has no runtime tests - if it compiles, the test passes.
+
+if not add_languages('cpp', required: false, native: false)
+ subdir_done()
+endif
+
+cpp = meson.get_compiler('cpp')
+
+# MSVC requires C++20 for designated initializers used in PG_MODULE_MAGIC and
+# other macros. Skip if the compiler doesn't support them.
+if not cpp.compiles('''
+ struct Foo { int a; int b; };
+ Foo f = {.a = 1, .b = 2};
+ ''',
+ name: 'C++ designated initializers')
+ subdir_done()
+endif
+
+test_cplusplusext_sources = files(
+ 'test_cplusplusext.cpp',
+)
+
+if host_system == 'windows'
+ test_cplusplusext_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
+ '--NAME', 'test_cplusplusext',
+ '--FILEDESC', 'test_cplusplusext - test C++ compatibility of PostgreSQL headers',])
+endif
+
+test_cplusplusext = shared_module('test_cplusplusext',
+ test_cplusplusext_sources,
+ kwargs: pg_test_mod_args,
+)
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
new file mode 100644
index 00000000000..012db8b7959
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -0,0 +1,51 @@
+/*--------------------------------------------------------------------------
+ *
+ * test_cplusplusext.cpp
+ * Test that PostgreSQL headers compile with a C++ compiler.
+ *
+ * This file is compiled with a C++ compiler to verify that PostgreSQL
+ * headers remain compatible with C++ extensions.
+ *
+ * Copyright (c) 2025-2026, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+ *
+ * -------------------------------------------------------------------------
+ */
+
+extern "C" {
+#include "postgres.h"
+#include "fmgr.h"
+#include "nodes/pg_list.h"
+#include "nodes/parsenodes.h"
+
+PG_MODULE_MAGIC;
+
+PG_FUNCTION_INFO_V1(test_cplusplus_compat);
+}
+
+StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
+
+extern "C" Datum
+test_cplusplus_compat(PG_FUNCTION_ARGS)
+{
+ List *node_list = list_make1(makeNode(RangeTblRef));
+ RangeTblRef *copy = copyObject(linitial_node(RangeTblRef, node_list));
+
+ foreach_ptr(RangeTblRef, rtr, node_list) {
+ rtr->rtindex++;
+ }
+
+ foreach_node(RangeTblRef, rtr, node_list) {
+ rtr->rtindex++;
+ }
+
+ StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
+ (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+
+ pfree(copy);
+ list_free_deep(node_list);
+
+ PG_RETURN_VOID();
+}
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-01-14 15:59 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-01-14 15:59 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 10.01.26 12:09, Jelte Fennema-Nio wrote:
> On Sat Jan 3, 2026 at 10:32 AM CET, Jelte Fennema-Nio wrote:
>> Attached is a patchset that does that. It required a few more fixes to
>> make the extension compile on MSVC too.
>
> Rebased after Peter merged the C++ improvements from the other thread.
I have a couple of comments on the sample extension module.
I think this module should have a runtime test, too. Otherwise you
don't know that you got the linkage correct, or whether this works at
all. It doesn't have to do much, like it could literally be a + b, and
it could evolve in the future to test hooks, _PG_init, etc.
Let's put a README file in the module's directory instead of putting the
explanation into the Makefile/meson.build.
I wonder if the module's build integration would work correctly in the
autoconf/makefile case if no C++ is available. AFAICT, it would fail to
build with g++ not found or similar.
AFAICT, the minimum changes to get a minimum test module to work are
- fix for "restrict", recently committed
- disable warning about zero-length arrays, seems trivial
- named designated initializers
I learned that named designated initializers in C++ are not allowed to
be specified out of order, so they are not a full equivalent to the C
syntax. This could be a problem for example if someone wanted in the
future to have something like
PG_MODULE_MAGIC_EXT(.threads_supported = true)
(while not specifying the leading .name and .version fields).
I think for now the easiest fix would be to just not use the named
initializers in the definition of PG_MODULE_MAGIC_DATA. Then we don't
need to require C++20 and have that additional code. In the future, we
might need a different solution more suitable for C++.
The use of -std=c++11 for CI is a valid idea; I have often wanted that
for C as well. But conversely we also want to allow testing optional
extension and future C standard features. So we need a comprehensive
solution there that covers both ends and both languages. Let's leave
that out for now and think about it separately.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-17 15:25 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-17 15:25 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Wed, 14 Jan 2026 at 16:59, Peter Eisentraut <peter@eisentraut.org> wrote:
> I think this module should have a runtime test, too. Otherwise you
> don't know that you got the linkage correct, or whether this works at
> all. It doesn't have to do much, like it could literally be a + b, and
> it could evolve in the future to test hooks, _PG_init, etc.
Done
> Let's put a README file in the module's directory instead of putting the
> explanation into the Makefile/meson.build.
Done
> I wonder if the module's build integration would work correctly in the
> autoconf/makefile case if no C++ is available. AFAICT, it would fail to
> build with g++ not found or similar.
Changed this to check that if CXX is g++, the command is also actually
available before including the module for the build.
> AFAICT, the minimum changes to get a minimum test module to work are
>
> - fix for "restrict", recently committed
> - disable warning about zero-length arrays, seems trivial
> - named designated initializers
Correct, I've now restructured the commits to have the module
introduction as the first one. Then all the other commits, both fix a
macro to work in C++ and add some usage of those macros as coverage to
the previously added module.
> I learned that named designated initializers in C++ are not allowed to
> be specified out of order, so they are not a full equivalent to the C
> syntax. This could be a problem for example if someone wanted in the
> future to have something like
>
> PG_MODULE_MAGIC_EXT(.threads_supported = true)
>
> (while not specifying the leading .name and .version fields).
This would still work fine, because fields are left out. The problem
occurs when defining values for fields, but in a different order than
the fields are specified in the struct (so e.g. by putting .version
before .name). The reason for that is related to destructor ordering.
> I think for now the easiest fix would be to just not use the named
> initializers in the definition of PG_MODULE_MAGIC_DATA. Then we don't
> need to require C++20 and have that additional code. In the future, we
> might need a different solution more suitable for C++.
There is a small problem with this though. Using both designated an
non-designated initializers, is not valid standard C++. I even get a
warning (but no error) about that with clang:
../src/test/modules/test_cplusplusext/test_cplusplusext.cpp:24:2: warning: mixture of designated and non-designated initializers in the same initializer list is a C99 extension [-Wc99-designator]
In C mixing them is allowed just fine.
Sadly that means that C++ extensions (even when compiled for C++20)
shouldn't use PG_MODULE_MAGIC_EXT with designated initializers at all.
I've updated the documentation to reflect that. I agree that it's better
to avoid requiring C++20 on MSVC (at least for now).
> The use of -std=c++11 for CI is a valid idea; I have often wanted that
> for C as well. But conversely we also want to allow testing optional
> extension and future C standard features. So we need a comprehensive
> solution there that covers both ends and both languages. Let's leave
> that out for now and think about it separately.
Removed
Attachments: download all (5 files, .tar.gz)
v6-0001-tests-Add-a-test-C-extension-module.patch (text/x-patch, 12.1K) download
From 6ece40b64ad1dcf44746680b07618ee783dd7e3b Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Fri, 2 Jan 2026 22:31:05 +0100
Subject: [PATCH v6 1/5] tests: Add a test C++ extension module
While we already test that our headers are valid C++ using headerscheck,
it turns out that the macros we define might still expand to invalid
C++ code. This adds a minimal test extension that is compiled using C++
to test that it's actually possible to build and run extensions written
in C++. Future commits will improve C++ compatibility of some of our
macros and add usage of them to this extension make sure that they don't
regress in the future.
To get CI green, this also fixes an issue when compiling C++ extensions
on MSVC: Our use of designated initializers in PG_MODULE_MAGIC_DATA
caused it to only be possible. This reverts to using positional
initializers instead. Sadly that means that using designated
initializers in C++20 is still not allowed in PG_MODULE_MAGIC_EXT
because mixing designated an positional initializers is a C only
feature.
---
doc/src/sgml/xfunc.sgml | 6 +++
meson.build | 4 ++
src/include/fmgr.h | 12 +++---
src/test/modules/Makefile | 11 ++++++
src/test/modules/meson.build | 1 +
src/test/modules/test_cplusplusext/.gitignore | 3 ++
src/test/modules/test_cplusplusext/Makefile | 26 +++++++++++++
src/test/modules/test_cplusplusext/README | 10 +++++
.../expected/test_cplusplusext.out | 14 +++++++
.../modules/test_cplusplusext/meson.build | 37 +++++++++++++++++++
.../sql/test_cplusplusext.sql | 6 +++
.../test_cplusplusext--1.0.sql | 8 ++++
.../test_cplusplusext.control | 4 ++
.../test_cplusplusext/test_cplusplusext.cpp | 37 +++++++++++++++++++
14 files changed, 174 insertions(+), 5 deletions(-)
create mode 100644 src/test/modules/test_cplusplusext/.gitignore
create mode 100644 src/test/modules/test_cplusplusext/Makefile
create mode 100644 src/test/modules/test_cplusplusext/README
create mode 100644 src/test/modules/test_cplusplusext/expected/test_cplusplusext.out
create mode 100644 src/test/modules/test_cplusplusext/meson.build
create mode 100644 src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql
create mode 100644 src/test/modules/test_cplusplusext/test_cplusplusext--1.0.sql
create mode 100644 src/test/modules/test_cplusplusext/test_cplusplusext.control
create mode 100644 src/test/modules/test_cplusplusext/test_cplusplusext.cpp
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index 70e815b8a2c..143f87a253a 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1973,6 +1973,12 @@ PG_MODULE_MAGIC_EXT(
.name = "my_module_name",
.version = "1.2.3"
);
+</programlisting>
+
+ In C++ code, use positional arguments instead of designated initializers:
+
+<programlisting>
+PG_MODULE_MAGIC_EXT("my_module_name", "1.2.3");
</programlisting>
Subsequently the name and version can be examined via
diff --git a/meson.build b/meson.build
index 6d304f32fb0..aef791da7c3 100644
--- a/meson.build
+++ b/meson.build
@@ -2211,6 +2211,10 @@ if cc.get_id() == 'msvc'
'/w24777', # 'function' : format string 'string' requires an argument of type 'type1', but variadic argument number has type 'type2' [like -Wformat]
]
+ cxxflags_warn += [
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union
+ ]
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index eabbc78b280..1ab8749cee1 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -497,13 +497,15 @@ typedef struct
}
/*
- * Macro to fill a magic block. If any arguments are given, they should
- * be field initializers.
+ * Macro to fill a magic block. If any arguments are given, they should be
+ * field initializers. These can be designated initialzers, or non-designated
+ * initializers. If they're non-designated, they are applied after the ABI
+ * fields.
*/
#define PG_MODULE_MAGIC_DATA(...) \
{ \
- .len = sizeof(Pg_magic_struct), \
- .abi_fields = PG_MODULE_ABI_DATA, \
+ sizeof(Pg_magic_struct), \
+ PG_MODULE_ABI_DATA, \
__VA_ARGS__ \
}
@@ -524,7 +526,7 @@ extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
const Pg_magic_struct * \
PG_MAGIC_FUNCTION_NAME(void) \
{ \
- static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA(.name = NULL); \
+ static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA(); \
return &Pg_magic_data; \
} \
extern int no_such_variable
diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile
index 4c6d56d97d8..c90b1bd0dc0 100644
--- a/src/test/modules/Makefile
+++ b/src/test/modules/Makefile
@@ -75,5 +75,16 @@ else
ALWAYS_SUBDIRS += ldap_password_func
endif
+# test_cplusplusext requires a working C++ compiler. If CXX is set to g++, then
+# that could be because g++ is AC_PROG_CXX's fallback when no C++ compiler is
+# found. So in that case we do check to see if it actually exists.
+ifneq ($(CXX),g++)
+SUBDIRS += test_cplusplusext
+else ifneq ($(shell command -v $(CXX)),)
+SUBDIRS += test_cplusplusext
+else
+ALWAYS_SUBDIRS += test_cplusplusext
+endif
+
$(recurse)
$(recurse_always)
diff --git a/src/test/modules/meson.build b/src/test/modules/meson.build
index 1b31c5b98d6..0c7e8ad4856 100644
--- a/src/test/modules/meson.build
+++ b/src/test/modules/meson.build
@@ -19,6 +19,7 @@ subdir('test_aio')
subdir('test_binaryheap')
subdir('test_bitmapset')
subdir('test_bloomfilter')
+subdir('test_cplusplusext')
subdir('test_cloexec')
subdir('test_copy_callbacks')
subdir('test_custom_rmgrs')
diff --git a/src/test/modules/test_cplusplusext/.gitignore b/src/test/modules/test_cplusplusext/.gitignore
new file mode 100644
index 00000000000..913175ff6e6
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/.gitignore
@@ -0,0 +1,3 @@
+/log/
+/results/
+/tmp_check/
diff --git a/src/test/modules/test_cplusplusext/Makefile b/src/test/modules/test_cplusplusext/Makefile
new file mode 100644
index 00000000000..88cd4403823
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/Makefile
@@ -0,0 +1,26 @@
+# src/test/modules/test_cplusplusext/Makefile
+
+MODULE_big = test_cplusplusext
+OBJS = \
+ $(WIN32RES) \
+ test_cplusplusext.o
+PGFILEDESC = "test_cplusplusext - test C++ compatibility of PostgreSQL headers"
+
+EXTENSION = test_cplusplusext
+DATA = test_cplusplusext--1.0.sql
+
+REGRESS = test_cplusplusext
+
+# Use C++ compiler for linking because this module includes C++ files
+override COMPILER = $(CXX) $(CXXFLAGS)
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = src/test/modules/test_cplusplusext
+top_builddir = ../../../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/src/test/modules/test_cplusplusext/README b/src/test/modules/test_cplusplusext/README
new file mode 100644
index 00000000000..c7a54fe8e7f
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/README
@@ -0,0 +1,10 @@
+test_cplusplusext - Test C++ Extension Compatibility
+====================================================
+
+This test module verifies that PostgreSQL headers and macros work correctly
+when compiled with a C++ compiler.
+
+While PostgreSQL already tests that headers are syntactically valid C++ using
+headerscheck, the macros defined in those headers might still expand to invalid
+C++ code. This module catches such issues by actually compiling and running an
+extension that's written in C++.
diff --git a/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out b/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out
new file mode 100644
index 00000000000..25600cfd1b4
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out
@@ -0,0 +1,14 @@
+CREATE EXTENSION test_cplusplusext;
+SELECT test_cplusplus_add(1, 2);
+ test_cplusplus_add
+--------------------
+ 3
+(1 row)
+
+SELECT module_name, version FROM pg_get_loaded_modules()
+ WHERE module_name = 'test_cplusplusext';
+ module_name | version
+-------------------+---------
+ test_cplusplusext | 1.2
+(1 row)
+
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
new file mode 100644
index 00000000000..0ddb67978ef
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -0,0 +1,37 @@
+# Copyright (c) 2025-2026, PostgreSQL Global Development Group
+
+if not add_languages('cpp', required: false, native: false)
+ subdir_done()
+endif
+
+test_cplusplusext_sources = files(
+ 'test_cplusplusext.cpp',
+)
+
+if host_system == 'windows'
+ test_cplusplusext_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
+ '--NAME', 'test_cplusplusext',
+ '--FILEDESC', 'test_cplusplusext - test C++ compatibility of PostgreSQL headers',])
+endif
+
+test_cplusplusext = shared_module('test_cplusplusext',
+ test_cplusplusext_sources,
+ kwargs: pg_test_mod_args,
+)
+test_install_libs += test_cplusplusext
+
+test_install_data += files(
+ 'test_cplusplusext.control',
+ 'test_cplusplusext--1.0.sql',
+)
+
+tests += {
+ 'name': 'test_cplusplusext',
+ 'sd': meson.current_source_dir(),
+ 'bd': meson.current_build_dir(),
+ 'regress': {
+ 'sql': [
+ 'test_cplusplusext',
+ ],
+ },
+}
diff --git a/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql b/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql
new file mode 100644
index 00000000000..693910ba637
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql
@@ -0,0 +1,6 @@
+CREATE EXTENSION test_cplusplusext;
+
+SELECT test_cplusplus_add(1, 2);
+
+SELECT module_name, version FROM pg_get_loaded_modules()
+ WHERE module_name = 'test_cplusplusext';
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext--1.0.sql b/src/test/modules/test_cplusplusext/test_cplusplusext--1.0.sql
new file mode 100644
index 00000000000..c54acb76823
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext--1.0.sql
@@ -0,0 +1,8 @@
+/* src/test/modules/test_cplusplusext/test_cplusplusext--1.0.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION test_cplusplusext" to load this file. \quit
+
+CREATE FUNCTION test_cplusplus_add(int4, int4) RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT;
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.control b/src/test/modules/test_cplusplusext/test_cplusplusext.control
new file mode 100644
index 00000000000..640a0a51f35
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.control
@@ -0,0 +1,4 @@
+comment = 'Test module for C++ extension compatibility'
+default_version = '1.0'
+module_pathname = '$libdir/test_cplusplusext'
+relocatable = true
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
new file mode 100644
index 00000000000..7108e5b1cc5
--- /dev/null
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -0,0 +1,37 @@
+/*--------------------------------------------------------------------------
+ *
+ * test_cplusplusext.cpp
+ * Test that PostgreSQL headers compile with a C++ compiler.
+ *
+ * This file is compiled with a C++ compiler to verify that PostgreSQL
+ * headers remain compatible with C++ extensions.
+ *
+ * Copyright (c) 2025-2026, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+ *
+ * -------------------------------------------------------------------------
+ */
+
+extern "C" {
+#include "postgres.h"
+#include "fmgr.h"
+
+PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
+
+PG_FUNCTION_INFO_V1(test_cplusplus_add);
+}
+
+/*
+ * Simple function that returns the sum of two integers. This verifies that
+ * C++ extension modules can be loaded and called correctly at runtime.
+ */
+extern "C" Datum
+test_cplusplus_add(PG_FUNCTION_ARGS)
+{
+ int32 a = PG_GETARG_INT32(0);
+ int32 b = PG_GETARG_INT32(1);
+
+ PG_RETURN_INT32(a + b);
+}
base-commit: 6831cd9e3b082d7b830c3196742dd49e3540c49b
--
2.52.0
v6-0002-Support-using-copyObject-in-C.patch (text/x-patch, 2.9K) download
From 923e443ff3724188ba13c93337b07378e4860d9a 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 v6 2/5] Support using copyObject in C++
Calling copyObject in C++ without GNU extensions fails with an error
like this:
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 name 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 ++--
.../modules/test_cplusplusext/test_cplusplusext.cpp | 6 ++++++
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 7136102e5ff..a0b1261f7d3 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -412,6 +412,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 b6ad28618ab..f5e17e670b7 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
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 7108e5b1cc5..48741f27949 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -17,6 +17,7 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
+#include "nodes/parsenodes.h"
PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
@@ -32,6 +33,11 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
{
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
+ RangeTblRef *node = makeNode(RangeTblRef);
+ RangeTblRef *copy = copyObject(node);
+
+ pfree(copy);
+ pfree(node);
PG_RETURN_INT32(a + b);
}
--
2.52.0
v6-0003-Use-pg_exprtype-instead-of-typeof.patch (text/x-patch, 3.1K) download
From ac5cbcfc21a2b91f646fbd636e94c79c5bc2f9b8 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v6 3/5] Use pg_exprtype instead of typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index a0b1261f7d3..65173b9d9fd 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -978,10 +978,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define AssertVariableIsOfType(varname, typename) \
- StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertStmt(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \
@@ -1229,11 +1229,11 @@ typedef struct PGAlignedXLogBlock
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index aeb17fa24a5..3e03d34d9ad 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,10 +38,10 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
- (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
#define relptr_access(base, rp) \
@@ -68,10 +68,10 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
- AssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
+ AssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
#define relptr_store(base, rp, val) \
--
2.52.0
v6-0004-Support-using-StaticAssert-macros-in-C.patch (text/x-patch, 2.5K) download
From 67f5f506dd13bac5e54790e864511c9eb3f5d88b Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 17 Jan 2026 14:51:36 +0100
Subject: [PATCH v6 4/5] Support using StaticAssert macros in C++
StaticAssertExpr didn't work in MSVC C++. This adds a dedicated C++
definition which uses an inline lamdbda, that calls only the static
assert. Since this results in empty lambda, the actual call will be
removed by any compiler that does some optimization.
---
src/include/c.h | 8 ++++++--
src/test/modules/test_cplusplusext/test_cplusplusext.cpp | 5 +++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 65173b9d9fd..03764571dc8 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -956,13 +956,17 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
static_assert(condition, errmessage)
#define StaticAssertStmt(condition, errmessage) \
do { static_assert(condition, errmessage); } while(0)
-#ifdef HAVE_STATEMENT_EXPRESSIONS
+#ifdef __cplusplus
+/* C++11 lambdas provide a convenient way to use static_assert as an expression */
+#define StaticAssertExpr(condition, errmessage) \
+ ((void) ([](){ static_assert(condition, errmessage); }(), 0))
+#elif defined(HAVE_STATEMENT_EXPRESSIONS)
#define StaticAssertExpr(condition, errmessage) \
((void) ({ static_assert(condition, errmessage); true; }))
#else
#define StaticAssertExpr(condition, errmessage) \
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
-#endif /* HAVE_STATEMENT_EXPRESSIONS */
+#endif
/*
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 48741f27949..bb9c310504e 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -24,6 +24,8 @@ PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
PG_FUNCTION_INFO_V1(test_cplusplus_add);
}
+StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
+
/*
* Simple function that returns the sum of two integers. This verifies that
* C++ extension modules can be loaded and called correctly at runtime.
@@ -36,6 +38,9 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
RangeTblRef *node = makeNode(RangeTblRef);
RangeTblRef *copy = copyObject(node);
+ StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
+ (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+
pfree(copy);
pfree(node);
--
2.52.0
v6-0005-Support-using-list_make-macros-in-C.patch (text/x-patch, 2.9K) download
From fb4f07ba3ce998c5c2358e2434fea6825fe3edbe Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 17 Jan 2026 14:55:28 +0100
Subject: [PATCH v6 5/5] Support using list_make macros in C++
The list_make_xxx_cell macros were using designated initializers and
these are only officially available in C++20. GCC and Clang allow them
in earlier C++ versions too, but MSVC is strict about it. Since we want
to support C++11 this changes these macros to use inline functions
instead, which work across both C and C++.
---
src/include/nodes/pg_list.h | 43 ++++++++++++++++---
.../test_cplusplusext/test_cplusplusext.cpp | 14 ++++++
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..ba43d36bc89 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -202,12 +202,45 @@ list_length(const List *l)
#define llast_node(type,l) castNode(type, llast(l))
/*
- * Convenience macros for building fixed-length lists
+ * Convenience functions for building fixed-length lists. These cannot be
+ * macros with designated initializers, because we want these functions to be
+ * usable from C++ versions below C++20.
*/
-#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
+static inline ListCell
+list_make_ptr_cell(void *v)
+{
+ ListCell c;
+
+ c.ptr_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_int_cell(int v)
+{
+ ListCell c;
+
+ c.int_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_oid_cell(Oid v)
+{
+ ListCell c;
+
+ c.oid_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_xid_cell(TransactionId v)
+{
+ ListCell c;
+
+ c.xid_value = v;
+ return c;
+}
#define list_make1(x1) \
list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index bb9c310504e..2bdf2c3d057 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -17,6 +17,7 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
+#include "nodes/pg_list.h"
#include "nodes/parsenodes.h"
PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
@@ -41,6 +42,19 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
(void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+ List *list = list_make1(node);
+
+ foreach_ptr(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ foreach_node(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ list_free(list);
pfree(copy);
pfree(node);
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-01-20 16:28 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-20 16:38 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 2 replies; 51+ messages in thread
From: Peter Eisentraut @ 2026-01-20 16:28 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 17.01.26 16:25, Jelte Fennema-Nio wrote:
>> AFAICT, the minimum changes to get a minimum test module to work are
>>
>> - fix for "restrict", recently committed
>> - disable warning about zero-length arrays, seems trivial
>> - named designated initializers
>
> Correct, I've now restructured the commits to have the module
> introduction as the first one. Then all the other commits, both fix a
> macro to work in C++ and add some usage of those macros as coverage to
> the previously added module.
I have split your first patch further. For a start, I left out the
PG_MODULE_MAGIC*-related changes and disabled the module under MSVC.
This has been committed. I plan to let the buildfarm run with it for a
day or two and then add in the basic MSVC support.
I implemented a different solution for checking whether C++ is available
under configure. The runtime check from the makefile looked a bit
fragile. This way, we now have a "have_cxx" variable available in both
meson and makefiles.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-20 16:38 ` Andres Freund <andres@anarazel.de>
2026-01-20 19:07 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
1 sibling, 1 reply; 51+ messages in thread
From: Andres Freund @ 2026-01-20 16:38 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 2026-01-20 17:28:00 +0100, Peter Eisentraut wrote:
> On 17.01.26 16:25, Jelte Fennema-Nio wrote:
> > > AFAICT, the minimum changes to get a minimum test module to work are
> > >
> > > - fix for "restrict", recently committed
> > > - disable warning about zero-length arrays, seems trivial
> > > - named designated initializers
> >
> > Correct, I've now restructured the commits to have the module
> > introduction as the first one. Then all the other commits, both fix a
> > macro to work in C++ and add some usage of those macros as coverage to
> > the previously added module.
>
> I have split your first patch further. For a start, I left out the
> PG_MODULE_MAGIC*-related changes and disabled the module under MSVC. This
> has been committed. I plan to let the buildfarm run with it for a day or
> two and then add in the basic MSVC support.
Seems like billbug doesn't like this:
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=billbug&dt=2026-01-20%2016%3A00%3A02
gmake[1]: Entering directory '/home/marcel/build-farm-20/buildroot/HEAD/pgsql.build/src/test/modules/test_cplusplusext'
g++ -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -I. -I. -I../../../../src/include -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS -I/usr/openssl/3/include -I/usr/include/libxml2 -c -o test_cplusplusext.o test_cplusplusext.cpp
In file included from ../../../../src/include/postgres.h:48,
from test_cplusplusext.cpp:18:
../../../../src/include/c.h:158:21: error: '_Noreturn' does not name a type; did you mean 'pg_noreturn'?
158 | #define pg_noreturn _Noreturn
| ^~~~~~~~~
../../../../src/include/c.h:918:1: note: in expansion of macro 'pg_noreturn'
918 | pg_noreturn extern void ExceptionalCondition(const char *conditionName,
| ^~~~~~~~~~~
../../../../src/include/lib/stringinfo.h: In function 'void initStringInfoFromString(StringInfo, char*, int)':
../../../../src/include/c.h:890:25: error: 'ExceptionalCondition' was not declared in this scope
890 | ExceptionalCondition(#condition, __FILE__, __LINE__); \\
| ^~~~~~~~~~~~~~~~~~~~
../../../../src/include/lib/stringinfo.h:177:9: note: in expansion of macro 'Assert'
177 | Assert(data[len] == '\\0');
| ^~~~~~
../../../../src/include/utils/elog.h: At global scope:
../../../../src/include/c.h:158:21: error: '_Noreturn' does not name a type; did you mean 'pg_noreturn'?
158 | #define pg_noreturn _Noreturn
| ^~~~~~~~~
../../../../src/include/utils/elog.h:471:1: note: in expansion of macro 'pg_noreturn'
471 | pg_noreturn extern void ReThrowError(ErrorData *edata);
| ^~~~~~~~~~~
../../../../src/include/c.h:158:21: error: '_Noreturn' does not name a type; did you mean 'pg_noreturn'?
158 | #define pg_noreturn _Noreturn
| ^~~~~~~~~
../../../../src/include/utils/elog.h:473:1: note: in expansion of macro 'pg_noreturn'
473 | pg_noreturn extern void pg_re_throw(void);
| ^~~~~~~~~~~
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-20 16:38 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
@ 2026-01-20 19:07 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-20 19:15 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-01-20 19:07 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 20.01.26 17:38, Andres Freund wrote:
>> I have split your first patch further. For a start, I left out the
>> PG_MODULE_MAGIC*-related changes and disabled the module under MSVC. This
>> has been committed. I plan to let the buildfarm run with it for a day or
>> two and then add in the basic MSVC support.
> Seems like billbug doesn't like this:
>
> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?
> nm=billbug&dt=2026-01-20%2016%3A00%3A02
>
> gmake[1]: Entering directory '/home/marcel/build-farm-20/buildroot/HEAD/pgsql.build/src/test/modules/test_cplusplusext'
> g++ -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -I. -I. -I../../../../src/include -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS -I/usr/openssl/3/include -I/usr/include/libxml2 -c -o test_cplusplusext.o test_cplusplusext.cpp
> In file included from ../../../../src/include/postgres.h:48,
> from test_cplusplusext.cpp:18:
> ../../../../src/include/c.h:158:21: error: '_Noreturn' does not name a type; did you mean 'pg_noreturn'?
> 158 | #define pg_noreturn _Noreturn
> | ^~~~~~~~~
> ../../../../src/include/c.h:918:1: note: in expansion of macro 'pg_noreturn'
> 918 | pg_noreturn extern void ExceptionalCondition(const char *conditionName,
> | ^~~~~~~~~~~
It's getting confused by _Noreturn, which is defined thus:
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define pg_noreturn _Noreturn
But apparently on these Solaris-related platforms, g++ defines
__STDC_VERSION__ even in C++ mode. (Confirmed in local testing.)
Apparently, this is even allowed by the C++ standard.
So the smallest fix is probably to gate this more like this:
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) &&
!defined(__cplusplus)
#define pg_noreturn _Noreturn
(Eventually, we could add support for C++ attributes, but one step at a
time.)
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-20 16:38 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-20 19:07 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-20 19:15 ` Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 51+ messages in thread
From: Andres Freund @ 2026-01-20 19:15 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
Hi,
On 2026-01-20 20:07:15 +0100, Peter Eisentraut wrote:
> On 20.01.26 17:38, Andres Freund wrote:
> > > I have split your first patch further. For a start, I left out the
> > > PG_MODULE_MAGIC*-related changes and disabled the module under MSVC. This
> > > has been committed. I plan to let the buildfarm run with it for a day or
> > > two and then add in the basic MSVC support.
> > Seems like billbug doesn't like this:
> >
> > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?
> > nm=billbug&dt=2026-01-20%2016%3A00%3A02
> >
> > gmake[1]: Entering directory '/home/marcel/build-farm-20/buildroot/HEAD/pgsql.build/src/test/modules/test_cplusplusext'
> > g++ -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O2 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -I. -I. -I../../../../src/include -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS -I/usr/openssl/3/include -I/usr/include/libxml2 -c -o test_cplusplusext.o test_cplusplusext.cpp
> > In file included from ../../../../src/include/postgres.h:48,
> > from test_cplusplusext.cpp:18:
> > ../../../../src/include/c.h:158:21: error: '_Noreturn' does not name a type; did you mean 'pg_noreturn'?
> > 158 | #define pg_noreturn _Noreturn
> > | ^~~~~~~~~
> > ../../../../src/include/c.h:918:1: note: in expansion of macro 'pg_noreturn'
> > 918 | pg_noreturn extern void ExceptionalCondition(const char *conditionName,
> > | ^~~~~~~~~~~
>
> It's getting confused by _Noreturn, which is defined thus:
>
> #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
> #define pg_noreturn _Noreturn
>
> But apparently on these Solaris-related platforms, g++ defines
> __STDC_VERSION__ even in C++ mode. (Confirmed in local testing.)
> Apparently, this is even allowed by the C++ standard.
Heh. Pretty odd to do that only on some platforms...
> So the smallest fix is probably to gate this more like this:
>
> #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) &&
> !defined(__cplusplus)
> #define pg_noreturn _Noreturn
>
> (Eventually, we could add support for C++ attributes, but one step at a
> time.)
Makes sense to me.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-25 12:42 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-04 15:54 ` Re: Make copyObject work in C++ Bryan Green <dbryan.green@gmail.com>
1 sibling, 2 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-25 12:42 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Tue Jan 20, 2026 at 5:28 PM CET, Peter Eisentraut wrote:
> I have split your first patch further. For a start, I left out the
> PG_MODULE_MAGIC*-related changes and disabled the module under MSVC.
> This has been committed. I plan to let the buildfarm run with it for a
> day or two and then add in the basic MSVC support.
To hopefully make your life a bit easier. Here's a rebased version that
enables the MSVC support again, with an updated commit message.
Attachments: download all (5 files, .tar.gz)
v7-0001-Support-building-C-extensions-with-MSVC.patch (text/x-patch, 5.6K) download
From 63397ed786c0feb42f9a29989f8c53fe0c9c07ec Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Fri, 2 Jan 2026 22:31:05 +0100
Subject: [PATCH v7 1/5] Support building C++ extensions with MSVC
In 476b35d4e31 a C++ test extension module was added. This test was
disabled for MSVC, because it failed to compile it in any C++ version
lower than C++20. The reason for that is our usage of designated
initializers in PG_MODULE_MAGIC_DATA (which was done in 9324c8c580).
Designated initialzers are only part of C++ from the C++20 standard
(although clang and gcc implemented support way earlier).
This reverts to using positional initializers in PG_MODULE_MAGIC_DATA so
that its possible to write C++ extensions in standard C++11. Sadly that
means that using designated initializers in C++20 is still not allowed
in PG_MODULE_MAGIC_EXT because mixing designated an positional
initializers is a C only feature. This restriction for C++ extensions is
now documented and tested.
---
doc/src/sgml/xfunc.sgml | 6 ++++++
meson.build | 4 ++++
src/include/fmgr.h | 12 +++++++-----
.../test_cplusplusext/expected/test_cplusplusext.out | 7 +++++++
src/test/modules/test_cplusplusext/meson.build | 5 -----
.../test_cplusplusext/sql/test_cplusplusext.sql | 3 +++
.../modules/test_cplusplusext/test_cplusplusext.cpp | 2 +-
7 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index 70e815b8a2c..143f87a253a 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1973,6 +1973,12 @@ PG_MODULE_MAGIC_EXT(
.name = "my_module_name",
.version = "1.2.3"
);
+</programlisting>
+
+ In C++ code, use positional arguments instead of designated initializers:
+
+<programlisting>
+PG_MODULE_MAGIC_EXT("my_module_name", "1.2.3");
</programlisting>
Subsequently the name and version can be examined via
diff --git a/meson.build b/meson.build
index df907b62da3..056412890b5 100644
--- a/meson.build
+++ b/meson.build
@@ -2238,6 +2238,10 @@ if cc.get_id() == 'msvc'
'/w24777', # 'function' : format string 'string' requires an argument of type 'type1', but variadic argument number has type 'type2' [like -Wformat]
]
+ cxxflags_warn += [
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union
+ ]
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index eabbc78b280..1ab8749cee1 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -497,13 +497,15 @@ typedef struct
}
/*
- * Macro to fill a magic block. If any arguments are given, they should
- * be field initializers.
+ * Macro to fill a magic block. If any arguments are given, they should be
+ * field initializers. These can be designated initialzers, or non-designated
+ * initializers. If they're non-designated, they are applied after the ABI
+ * fields.
*/
#define PG_MODULE_MAGIC_DATA(...) \
{ \
- .len = sizeof(Pg_magic_struct), \
- .abi_fields = PG_MODULE_ABI_DATA, \
+ sizeof(Pg_magic_struct), \
+ PG_MODULE_ABI_DATA, \
__VA_ARGS__ \
}
@@ -524,7 +526,7 @@ extern PGDLLEXPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
const Pg_magic_struct * \
PG_MAGIC_FUNCTION_NAME(void) \
{ \
- static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA(.name = NULL); \
+ static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA(); \
return &Pg_magic_data; \
} \
extern int no_such_variable
diff --git a/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out b/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out
index ab0b04b5c5e..25600cfd1b4 100644
--- a/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out
+++ b/src/test/modules/test_cplusplusext/expected/test_cplusplusext.out
@@ -5,3 +5,10 @@ SELECT test_cplusplus_add(1, 2);
3
(1 row)
+SELECT module_name, version FROM pg_get_loaded_modules()
+ WHERE module_name = 'test_cplusplusext';
+ module_name | version
+-------------------+---------
+ test_cplusplusext | 1.2
+(1 row)
+
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..24a9cf16dca 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -4,11 +4,6 @@ if not have_cxx
subdir_done()
endif
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
- subdir_done()
-endif
-
test_cplusplusext_sources = files(
'test_cplusplusext.cpp',
)
diff --git a/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql b/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql
index a41682417ae..693910ba637 100644
--- a/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql
+++ b/src/test/modules/test_cplusplusext/sql/test_cplusplusext.sql
@@ -1,3 +1,6 @@
CREATE EXTENSION test_cplusplusext;
SELECT test_cplusplus_add(1, 2);
+
+SELECT module_name, version FROM pg_get_loaded_modules()
+ WHERE module_name = 'test_cplusplusext';
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 435937c00d2..7108e5b1cc5 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -18,7 +18,7 @@ extern "C" {
#include "postgres.h"
#include "fmgr.h"
-PG_MODULE_MAGIC;
+PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
PG_FUNCTION_INFO_V1(test_cplusplus_add);
}
base-commit: 9b9eaf08ab2dc22c691b22e59f1574e0f1bcc822
--
2.52.0
v7-0002-Support-using-copyObject-in-C.patch (text/x-patch, 2.9K) download
From 2d7130aab09383c88ca8c98d666144df70d0f2da 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 v7 2/5] Support using copyObject in C++
Calling copyObject in C++ without GNU extensions fails with an error
like this:
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 name 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 ++--
.../modules/test_cplusplusext/test_cplusplusext.cpp | 6 ++++++
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index c0be07a4566..08490641906 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -412,6 +412,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 b6ad28618ab..f5e17e670b7 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
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 7108e5b1cc5..48741f27949 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -17,6 +17,7 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
+#include "nodes/parsenodes.h"
PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
@@ -32,6 +33,11 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
{
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
+ RangeTblRef *node = makeNode(RangeTblRef);
+ RangeTblRef *copy = copyObject(node);
+
+ pfree(copy);
+ pfree(node);
PG_RETURN_INT32(a + b);
}
--
2.52.0
v7-0003-Use-pg_exprtype-instead-of-typeof.patch (text/x-patch, 3.1K) download
From 4e7cf0efe82b5f73048c488ffb1fc6619d6dbb65 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v7 3/5] Use pg_exprtype instead of typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 08490641906..9c54a67506d 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -978,10 +978,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define AssertVariableIsOfType(varname, typename) \
- StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertStmt(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \
@@ -1229,11 +1229,11 @@ typedef struct PGAlignedXLogBlock
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index aeb17fa24a5..3e03d34d9ad 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,10 +38,10 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(AssertVariableIsOfTypeMacro(base, char *), \
- (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
#define relptr_access(base, rp) \
@@ -68,10 +68,10 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(AssertVariableIsOfTypeMacro(base, char *), \
- AssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
+ AssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
#define relptr_store(base, rp, val) \
--
2.52.0
v7-0004-Support-using-StaticAssert-macros-in-C.patch (text/x-patch, 2.5K) download
From bd3384dd449d68818573599201f66e7f7048174e Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 17 Jan 2026 14:51:36 +0100
Subject: [PATCH v7 4/5] Support using StaticAssert macros in C++
StaticAssertExpr didn't work in MSVC C++. This adds a dedicated C++
definition which uses an inline lamdbda, that calls only the static
assert. Since this results in empty lambda, the actual call will be
removed by any compiler that does some optimization.
---
src/include/c.h | 8 ++++++--
src/test/modules/test_cplusplusext/test_cplusplusext.cpp | 5 +++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 9c54a67506d..0e4befb9e85 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -956,13 +956,17 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
static_assert(condition, errmessage)
#define StaticAssertStmt(condition, errmessage) \
do { static_assert(condition, errmessage); } while(0)
-#ifdef HAVE_STATEMENT_EXPRESSIONS
+#ifdef __cplusplus
+/* C++11 lambdas provide a convenient way to use static_assert as an expression */
+#define StaticAssertExpr(condition, errmessage) \
+ ((void) ([](){ static_assert(condition, errmessage); }(), 0))
+#elif defined(HAVE_STATEMENT_EXPRESSIONS)
#define StaticAssertExpr(condition, errmessage) \
((void) ({ static_assert(condition, errmessage); true; }))
#else
#define StaticAssertExpr(condition, errmessage) \
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
-#endif /* HAVE_STATEMENT_EXPRESSIONS */
+#endif
/*
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 48741f27949..bb9c310504e 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -24,6 +24,8 @@ PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
PG_FUNCTION_INFO_V1(test_cplusplus_add);
}
+StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
+
/*
* Simple function that returns the sum of two integers. This verifies that
* C++ extension modules can be loaded and called correctly at runtime.
@@ -36,6 +38,9 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
RangeTblRef *node = makeNode(RangeTblRef);
RangeTblRef *copy = copyObject(node);
+ StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
+ (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+
pfree(copy);
pfree(node);
--
2.52.0
v7-0005-Support-using-list_make-macros-in-C.patch (text/x-patch, 2.9K) download
From dabaf5ef094b06a694f956f7b6749ade11c9b846 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 17 Jan 2026 14:55:28 +0100
Subject: [PATCH v7 5/5] Support using list_make macros in C++
The list_make_xxx_cell macros were using designated initializers and
these are only officially available in C++20. GCC and Clang allow them
in earlier C++ versions too, but MSVC is strict about it. Since we want
to support C++11 this changes these macros to use inline functions
instead, which work across both C and C++.
---
src/include/nodes/pg_list.h | 43 ++++++++++++++++---
.../test_cplusplusext/test_cplusplusext.cpp | 14 ++++++
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..ba43d36bc89 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -202,12 +202,45 @@ list_length(const List *l)
#define llast_node(type,l) castNode(type, llast(l))
/*
- * Convenience macros for building fixed-length lists
+ * Convenience functions for building fixed-length lists. These cannot be
+ * macros with designated initializers, because we want these functions to be
+ * usable from C++ versions below C++20.
*/
-#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
+static inline ListCell
+list_make_ptr_cell(void *v)
+{
+ ListCell c;
+
+ c.ptr_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_int_cell(int v)
+{
+ ListCell c;
+
+ c.int_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_oid_cell(Oid v)
+{
+ ListCell c;
+
+ c.oid_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_xid_cell(TransactionId v)
+{
+ ListCell c;
+
+ c.xid_value = v;
+ return c;
+}
#define list_make1(x1) \
list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index bb9c310504e..2bdf2c3d057 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -17,6 +17,7 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
+#include "nodes/pg_list.h"
#include "nodes/parsenodes.h"
PG_MODULE_MAGIC_EXT("test_cplusplusext", "1.2");
@@ -41,6 +42,19 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
(void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+ List *list = list_make1(node);
+
+ foreach_ptr(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ foreach_node(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ list_free(list);
pfree(copy);
pfree(node);
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-01-25 16:50 ` Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 1 reply; 51+ messages in thread
From: Andres Freund @ 2026-01-25 16:50 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
Hi,
On 2026-01-25 13:42:51 +0100, Jelte Fennema-Nio wrote:
> This reverts to using positional initializers in PG_MODULE_MAGIC_DATA so
> that its possible to write C++ extensions in standard C++11. Sadly that
> means that using designated initializers in C++20 is still not allowed
> in PG_MODULE_MAGIC_EXT because mixing designated an positional
> initializers is a C only feature. This restriction for C++ extensions is
> now documented and tested.
I'm pretty sceptical this is the right direction. We were going for designated
initializers for a reason, namely that we expect more arguments to be added
over time and perhaps eventually also to remove some. And this will just lead
to that being harder because we have to worry about C++ extensions.
But I'm also confused as to why it's needed - there's nomixing of designated
and non-designated initializers that I can see? If you use
PG_MODULE_MAGIC_EXT(.name = "whatnot"), it evaluates down to
extern __attribute__((visibility("default"))) const Pg_magic_struct *Pg_magic_func(void); const Pg_magic_struct * Pg_magic_func(void) { static const Pg_magic_struct Pg_magic_data = { .len = sizeof(Pg_magic_struct), .abi_fields = { 190000 / 100, 100, 32, 64, true, "PostgreSQL", }, .name="whatnot"}; return &Pg_magic_data; } extern int no_such_variable;
And indeed, contra to what you reported upthread, I can't get clang to report
a warning about that. I do obviously see warnings about the wrong order if I
pass the arguments in the wrong order, but that's a lot less problematic. And
omitted args don't trigger warnings, as you noted.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
@ 2026-01-25 17:52 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-26 10:29 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 2 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-25 17:52 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Sun Jan 25, 2026 at 5:50 PM CET, Andres Freund wrote:
> I'm pretty sceptical this is the right direction.
The only other option I can think of is not supporting C++ extension on
MSVC unless they are compiled with C++20 (or later). I don't
particularly care about Windows C++ extensions myself, so I personally
would be fine with that choice. It seems a bit harsh, though.
> We were going for designated
> initializers for a reason, namely that we expect more arguments to be added
> over time and perhaps eventually also to remove some. And this will just lead
> to that being harder because we have to worry about C++ extensions.
Adding new arguments (aka fields) should cause no problems. Assuming
we'd add them at the end of the Pg_magic_struct definition. Removing
ones seems like even for C you'd need different PG_MODULE_MAGIC_EXT
invocations depending on PG_VERSION_NUM. I don't see how using
positional args would make that harder.
> But I'm also confused as to why it's needed - there's nomixing of designated
> and non-designated initializers that I can see? If you use
> PG_MODULE_MAGIC_EXT(.name = "whatnot"), it evaluates down to
>
> extern __attribute__((visibility("default"))) const Pg_magic_struct *Pg_magic_func(void); const Pg_magic_struct * Pg_magic_func(void) { static const Pg_magic_struct Pg_magic_data = { .len = sizeof(Pg_magic_struct), .abi_fields = { 190000 / 100, 100, 32, 64, true, "PostgreSQL", }, .name="whatnot"}; return &Pg_magic_data; } extern int no_such_variable;
>
> And indeed, contra to what you reported upthread, I can't get clang to report
> a warning about that. I do obviously see warnings about the wrong order if I
> pass the arguments in the wrong order, but that's a lot less problematic. And
> omitted args don't trigger warnings, as you noted.
It sounds like I wasn't clear enough what the problem was. The main
problem currently is that MSVC C++ fails to compile a cpp file
containing PG_MODULE_MAGIC (or PG_MODULE_MAGIC_EXT) unless you use /std:c++20.
Afaict it would have been possible to do so before 9324c8c580 (aka
anything before PG18), but since that commit you need /std:c++20. The
fact that we haven't heard anyone complain so far, might be an indication
that not many people (or maybe anyone) is using C++ extensions on Windows.
The only way to make PG_MODULE_MAGIC work on MSVC pre-C++20 is to
partially revert 9324c8c580, and use positional arguments in the
definition of PG_MODULE_MAGIC_DATA again. Like I've done in v7-0001.
For C extensions v7-0001 has no downsides. However, after applying
v7-0001, C++ extensions that use PG_MODULE_MAGIC_EXT with designated
parameters will get the following warning on at least clang 18 on my
machine:
meson setup --prefix ~/.pgenv/pgsql-master --debug build --reconfigure -Dc_args='-fno-omit-frame-pointer' -Dcassert=true
meson test -C build --suite setup --suite test_cplusplusext
[2202/2268] Compiling C++ object src/test/modules/test_cplusplusext/test_cplusplusext.so.p/test_cplusplusext.cpp.o
../src/test/modules/test_cplusplusext/test_cplusplusext.cpp:23:21: warning: mixture of designated and non-designated initializers in the same initializer list is a C99 extension [-Wc99-designator]
23 | PG_MODULE_MAGIC_EXT(.name="test_cplusplusext",.version= "1.2");
| ^~~~~~~~~~~~~~~~~~~~~~~~~
../src/include/fmgr.h:548:24: note: expanded from macro 'PG_MODULE_MAGIC_EXT'
548 | PG_MODULE_MAGIC_DATA(__VA_ARGS__); \
| ^~~~~~~~~~~
../src/include/fmgr.h:509:2: note: expanded from macro 'PG_MODULE_MAGIC_DATA'
509 | __VA_ARGS__ \
| ^~~~~~~~~~~
../src/test/modules/test_cplusplusext/test_cplusplusext.cpp:23:1: note: first non-designated initializer is here
23 | PG_MODULE_MAGIC_EXT(.name="test_cplusplusext",.version= "1.2");
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/include/fmgr.h:548:3: note: expanded from macro 'PG_MODULE_MAGIC_EXT'
548 | PG_MODULE_MAGIC_DATA(__VA_ARGS__); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/include/fmgr.h:507:2: note: expanded from macro 'PG_MODULE_MAGIC_DATA'
507 | sizeof(Pg_magic_struct), \
| ^~~~~~~~~~~~~~~~~~~~~~~
Note that you need to use meson test, not meson install, otherwise
test_cplusplusext.cpp won't get compiled.
So to be clear, yes right now there's no mixing of designated and
non-designated initializers. But after applying v7-0001 there would be
when you use something like this:
PG_MODULE_MAGIC_EXT(.name="test_cplusplusext",.version= "1.2");
And while the C standard allows mixing designated and non-designated
initializerss, the C++ standard (even C++20) does not.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-01-25 20:06 ` Andres Freund <andres@anarazel.de>
2026-01-26 10:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 2 replies; 51+ messages in thread
From: Andres Freund @ 2026-01-25 20:06 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
Hi,
On 2026-01-25 18:52:37 +0100, Jelte Fennema-Nio wrote:
> On Sun Jan 25, 2026 at 5:50 PM CET, Andres Freund wrote:
> > We were going for designated
> > initializers for a reason, namely that we expect more arguments to be added
> > over time and perhaps eventually also to remove some. And this will just lead
> > to that being harder because we have to worry about C++ extensions.
>
> Adding new arguments (aka fields) should cause no problems. Assuming
> we'd add them at the end of the Pg_magic_struct definition. Removing
> ones seems like even for C you'd need different PG_MODULE_MAGIC_EXT
> invocations depending on PG_VERSION_NUM. I don't see how using
> positional args would make that harder.
Named args make that easier in two ways: First, only extensions using the
to-be-removed option will fail. Second, removal of options reliably generates
errors, rather than bogusly use one field for another, just because the types
are compatible.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
@ 2026-01-26 10:47 ` Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-26 10:47 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Sun, 25 Jan 2026 at 21:06, Andres Freund <andres@anarazel.de> wrote:
> Named args make that easier in two ways: First, only extensions using the
> to-be-removed option will fail. Second, removal of options reliably generates
> errors, rather than bogusly use one field for another, just because the types
> are compatible.
Fair enough, for removals it has some benefits. Still seems like a
relatively small win for something I don't expect us to be doing
anytime soon (name and version I expect to stay around forever).
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
@ 2026-02-13 10:28 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-17 09:24 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
1 sibling, 3 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-02-13 10:28 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Peter Eisentraut <peter@eisentraut.org>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Sun Jan 25, 2026 at 9:06 PM CET, Andres Freund wrote:
> Named args make that easier in two ways: First, only extensions using the
> to-be-removed option will fail. Second, removal of options reliably generates
> errors, rather than bogusly use one field for another, just because the types
> are compatible.
After discussing the topic in-person with Peter at FOSDEM. We agreed
that the best road forward was to not bother with MSVC for now. No-one
has actually expressed an interest in being able to build C++ extension
using MSVC, and the effort to support it is both non-trivial and not
without downsides to the rest of the codebase. We can always come back
to this later, possibly requiring C++20 on MSVC.
So I've removed that patch and now this patchset its goal is to improve
compatibiltity with the C++ flavor of GCC and Clang.
Patch 1 and 2 add some more macro calls to our test C++ extension. These
macros already work in GCC and Clang, this is purely to test for future
regressinos.
Patch 3 makes copyObject work when using GCC or Clang with -std=c++11 by
introducing pg_exprtype.
Patch 4 starts using pg_exprtype in more places.
I'm also working on some patches to support
StaticAssertVariableIsOfType, but I've run into some ICE compiler errors
of MSVC 2019.
Attachments: download all (4 files, .tar.gz)
v8-0001-Test-List-macros-in-C-extensions.patch (text/x-patch, 1.6K) download
From 8a5bbbd0e73edafc340c938ec6e234384dbe672a Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Fri, 13 Feb 2026 09:14:47 +0100
Subject: [PATCH v8 1/6] Test List macros in C++ extensions
All of these macros already work in C++ with Clang and GCC (the only
compilers we're currently testing C++ extension support for). This adds
a regression test for them in our test C++ extension, so we can safely
change their implementation without accidentally breaking C++. Some of
the List macros didn't work in C++ in the past (d5ca15ee5), this would
have caught that.
---
.../test_cplusplusext/test_cplusplusext.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 435937c00d2..f1a2ab7f2bf 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -17,6 +17,8 @@
extern "C" {
#include "postgres.h"
#include "fmgr.h"
+#include "nodes/pg_list.h"
+#include "nodes/primnodes.h"
PG_MODULE_MAGIC;
@@ -32,6 +34,21 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
{
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
+ RangeTblRef *node = makeNode(RangeTblRef);
+ List *list = list_make1(node);
+
+ foreach_ptr(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ foreach_node(RangeTblRef, rtr, list)
+ {
+ (void) rtr;
+ }
+
+ list_free(list);
+ pfree(node);
PG_RETURN_INT32(a + b);
}
base-commit: d7edcec35c7c28edb3bf283dfe9c892b042ca158
--
2.52.0
v8-0002-Test-most-StaticAssert-macros-in-C-extensions.patch (text/x-patch, 1.6K) download
From 8f9d2a63bcdf30a445cb24c5453f34d8f54a4b29 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sat, 17 Jan 2026 14:51:36 +0100
Subject: [PATCH v8 2/6] Test most StaticAssert macros in C++ extensions
Most of the StaticAssert macros already worked in C++ with Clang and GCC
(the only compilers we're currently testing C++ extension support for).
This adds a regression test for them in our test C++ extension, so we
can safely change their implementation without accidentally breaking
C++.
The only macros that StaticAssert macros that don't work yet are the
StaticAssertVariableIsOfType and StaticAssertVariableIsOfTypeMacro.
These will be added in a follow on commit.
---
src/test/modules/test_cplusplusext/test_cplusplusext.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index f1a2ab7f2bf..8c2eabcca43 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -25,6 +25,8 @@ PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(test_cplusplus_add);
}
+StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
+
/*
* Simple function that returns the sum of two integers. This verifies that
* C++ extension modules can be loaded and called correctly at runtime.
@@ -47,6 +49,9 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
(void) rtr;
}
+ StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
+ (void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+
list_free(list);
pfree(node);
--
2.52.0
v8-0003-Support-using-copyObject-in-C.patch (text/x-patch, 2.9K) download
From cb57b403ee7819f7512a5e5edcd4ce1cb876ee46 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 v8 3/6] Support using copyObject in C++
Calling copyObject in C++ without GNU extensions (e.g. then using
-std=c++11 instead of -std=gnu++11) fails with an error like this:
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 whether it's a C or C++ compiler. While
pg_typeof would have been a more natural name, that name 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 ++--
.../modules/test_cplusplusext/test_cplusplusext.cpp | 2 ++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 3fc09ec1e4a..9f418e432ea 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -412,6 +412,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 59a7df31aba..a03c85f1b01 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
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 8c2eabcca43..5e6c8f85f6f 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -37,6 +37,7 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
RangeTblRef *node = makeNode(RangeTblRef);
+ RangeTblRef *copy = copyObject(node);
List *list = list_make1(node);
foreach_ptr(RangeTblRef, rtr, list)
@@ -54,6 +55,7 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
list_free(list);
pfree(node);
+ pfree(copy);
PG_RETURN_INT32(a + b);
}
--
2.52.0
v8-0004-Use-pg_exprtype-instead-of-typeof.patch (text/x-patch, 3.2K) download
From d2986a90548f5dce7fbd6d0e09d7d881f15e3e53 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v8 4/6] Use pg_exprtype instead of typeof
The previous commit introduced pg_exprtype. This starts using that in a
few more places.
---
src/include/c.h | 8 ++++----
src/include/utils/relptr.h | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 9f418e432ea..b448a4a8775 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -978,10 +978,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define StaticAssertVariableIsOfType(varname, typename) \
- StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertDecl(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define StaticAssertVariableIsOfType(varname, typename) \
@@ -1245,11 +1245,11 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock;
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(pg_exprtype(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h
index 94975f2f237..2df6c673017 100644
--- a/src/include/utils/relptr.h
+++ b/src/include/utils/relptr.h
@@ -38,10 +38,10 @@
#define relptr_declare(type, relptrtype) \
typedef relptr(type) relptrtype
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_access(base, rp) \
(StaticAssertVariableIsOfTypeMacro(base, char *), \
- (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
+ (pg_exprtype((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
(base) + (rp).relptr_off - 1))
#else
#define relptr_access(base, rp) \
@@ -68,10 +68,10 @@ relptr_store_eval(char *base, char *val)
}
}
-#ifdef HAVE_TYPEOF
+#ifdef pg_exprtype
#define relptr_store(base, rp, val) \
(StaticAssertVariableIsOfTypeMacro(base, char *), \
- StaticAssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
+ StaticAssertVariableIsOfTypeMacro(val, pg_exprtype((rp).relptr_type)), \
(rp).relptr_off = relptr_store_eval((base), (char *) (val)))
#else
#define relptr_store(base, rp, val) \
--
2.52.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-02-17 09:24 ` Peter Eisentraut <peter@eisentraut.org>
2 siblings, 0 replies; 51+ messages in thread
From: Peter Eisentraut @ 2026-02-17 09:24 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On 13.02.26 11:28, Jelte Fennema-Nio wrote:
> On Sun Jan 25, 2026 at 9:06 PM CET, Andres Freund wrote:
>> Named args make that easier in two ways: First, only extensions using the
>> to-be-removed option will fail. Second, removal of options reliably
>> generates
>> errors, rather than bogusly use one field for another, just because
>> the types
>> are compatible.
>
> After discussing the topic in-person with Peter at FOSDEM. We agreed
> that the best road forward was to not bother with MSVC for now. No-one
> has actually expressed an interest in being able to build C++ extension
> using MSVC, and the effort to support it is both non-trivial and not
> without downsides to the rest of the codebase. We can always come back
> to this later, possibly requiring C++20 on MSVC.
>
> So I've removed that patch and now this patchset its goal is to improve
> compatibiltity with the C++ flavor of GCC and Clang.
>
> Patch 1 and 2 add some more macro calls to our test C++ extension. These
> macros already work in GCC and Clang, this is purely to test for future
> regressinos.
I have committed these two. I'll give them some time on the buildfarm
and then look at the rest.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-02-19 08:31 ` Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-02-19 08:31 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 13.02.26 11:28, Jelte Fennema-Nio wrote:
> Patch 3 makes copyObject work when using GCC or Clang with -std=c++11 by
> introducing pg_exprtype.
>
> Patch 4 starts using pg_exprtype in more places.
I found this paper
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2927.htm
which led to the addition of typeof into the C standard.
It contains a section 'Why not "decltype"?' that explains how decltype
is different, but it also explains that if typeof were added to C++,
then it would be
std::remove_reference_t<decltype(T)>
What I suggest we should do here is:
1. Add a configure test that checks if the C++ compiler supports typeof.
2. If not, #define typeof to the above expression.
Then code can continue to use typeof unchanged.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-02-20 09:47 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-02-20 09:47 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Thu Feb 19, 2026 at 9:31 AM CET, Peter Eisentraut wrote:
> What I suggest we should do here is:
>
> 1. Add a configure test that checks if the C++ compiler supports typeof.
>
> 2. If not, #define typeof to the above expression.
>
> Then code can continue to use typeof unchanged.
Makes total sense, I didn't realise decltype and typeof were not quite
the same thing. Attached is an updated patchset that does that.
It also includes a patch that improves unconstify and unvolatize by
using StaticAssertVariableIsOfTypeMacro instead of a custom version of
that assertion. (Like I said, in a future patch I intend to make
StaticAssertVariableIsOfTypeMacro work in C++ as well, but this seemed
like a good improvement anyway)
Attachments: download all (3 files, .tar.gz)
v9-0001-Support-using-copyObject-in-C.patch (text/x-patch, 7.7K) download
From 1ff9279f3acb207e23e8b20b23429283b81a94fb 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 v9 1/3] Support using copyObject in C++
Calling copyObject in C++ without GNU extensions (e.g. then using
-std=c++11 instead of -std=gnu++11) fails with an error like this:
error: use of undeclared identifier 'typeof'; did you mean 'typeid'
This is due to the C compiler used to compile postgres supporting
typeof, but that function actually not being present in the C++
compiler. This fixes that by explicitely checking for typeof support in
C++ and then either use that, or define typeof ourselves as:
std::remove_reference_t<decltype(x)>
According to the paper that led to adding typeof to the C standard,
that's the C++ equivalent of the C typeof:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2927.htm#existing-decltype
---
config/c-compiler.m4 | 29 ++++++++++
configure | 54 +++++++++++++++++++
configure.ac | 1 +
meson.build | 25 +++++++++
src/include/c.h | 21 ++++++++
src/include/pg_config.h.in | 4 ++
.../test_cplusplusext/test_cplusplusext.cpp | 2 +
7 files changed, 136 insertions(+)
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 1509dbfa2ab..5b3cbc7e8e8 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -193,6 +193,35 @@ fi])# PGAC_C_TYPEOF
+# PGAC_CXX_TYPEOF
+# ----------------
+# Check if the C++ compiler understands typeof or a variant. Define
+# HAVE_CXX_TYPEOF if so, and define 'pg_cxx_typeof' to the actual key word.
+#
+AC_DEFUN([PGAC_CXX_TYPEOF],
+[AC_CACHE_CHECK(for C++ typeof, pgac_cv_cxx_typeof,
+[pgac_cv_cxx_typeof=no
+AC_LANG_PUSH(C++)
+for pgac_kw in typeof __typeof__; do
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;])],
+[pgac_cv_cxx_typeof=$pgac_kw])
+ test "$pgac_cv_cxx_typeof" != no && break
+done
+AC_LANG_POP([])])
+if test "$pgac_cv_cxx_typeof" != no; then
+ AC_DEFINE(HAVE_CXX_TYPEOF, 1,
+ [Define to 1 if your C++ compiler understands `typeof' or something similar.])
+ if test "$pgac_cv_cxx_typeof" != typeof; then
+ AC_DEFINE_UNQUOTED(pg_cxx_typeof, $pgac_cv_cxx_typeof, [Define to how the C++ compiler spells `typeof'.])
+ fi
+fi])# PGAC_CXX_TYPEOF
+
+
+
# PGAC_C_TYPES_COMPATIBLE
# -----------------------
# Check if the C compiler understands __builtin_types_compatible_p,
diff --git a/configure b/configure
index e1a08129974..3995a16fd1c 100755
--- a/configure
+++ b/configure
@@ -14968,6 +14968,60 @@ _ACEOF
fi
fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ typeof" >&5
+$as_echo_n "checking for C++ typeof... " >&6; }
+if ${pgac_cv_cxx_typeof+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ pgac_cv_cxx_typeof=no
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+for pgac_kw in typeof __typeof__; do
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+ pgac_cv_cxx_typeof=$pgac_kw
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ test "$pgac_cv_cxx_typeof" != no && break
+done
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_cxx_typeof" >&5
+$as_echo "$pgac_cv_cxx_typeof" >&6; }
+if test "$pgac_cv_cxx_typeof" != no; then
+
+$as_echo "#define HAVE_CXX_TYPEOF 1" >>confdefs.h
+
+ if test "$pgac_cv_cxx_typeof" != typeof; then
+
+cat >>confdefs.h <<_ACEOF
+#define pg_cxx_typeof $pgac_cv_cxx_typeof
+_ACEOF
+
+ fi
+fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_types_compatible_p" >&5
$as_echo_n "checking for __builtin_types_compatible_p... " >&6; }
if ${pgac_cv__types_compatible+:} false; then :
diff --git a/configure.ac b/configure.ac
index cc85c233c03..754dc50d6ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1716,6 +1716,7 @@ PGAC_PRINTF_ARCHETYPE
PGAC_CXX_PRINTF_ARCHETYPE
PGAC_C_STATEMENT_EXPRESSIONS
PGAC_C_TYPEOF
+PGAC_CXX_TYPEOF
PGAC_C_TYPES_COMPATIBLE
PGAC_C_BUILTIN_CONSTANT_P
PGAC_C_BUILTIN_OP_OVERFLOW
diff --git a/meson.build b/meson.build
index 055e96315d0..06ab917365e 100644
--- a/meson.build
+++ b/meson.build
@@ -2882,6 +2882,31 @@ int main(void)
endif
endforeach
+# Check if the C++ compiler understands typeof or a variant.
+if have_cxx
+ foreach kw : ['typeof', '__typeof__']
+ if cxx.compiles('''
+int main(void)
+{
+ int x = 0;
+ @0@(x) y;
+ y = x;
+ return y;
+}
+'''.format(kw),
+ name: 'C++ ' + kw,
+ args: test_c_args, include_directories: postgres_inc)
+
+ cdata.set('HAVE_CXX_TYPEOF', 1)
+ if kw != 'typeof'
+ cdata.set('pg_cxx_typeof', kw)
+ endif
+
+ break
+ endif
+ endforeach
+endif
+
# MSVC doesn't cope well with defining restrict to __restrict, the
# spelling it understands, because it conflicts with
diff --git a/src/include/c.h b/src/include/c.h
index 7ee4751992f..c3b3e9eea4e 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -424,6 +424,27 @@
#define unlikely(x) ((x) != 0)
#endif
+/*
+ * Provide typeof in C++ for C++ compilers that don't support typeof natively.
+ * It might be spelled __typeof__ instead of typeof, in which case
+ * pg_cxx_typeof provides that mapping. If neither is supported, we can use
+ * decltype, but to make it equivalent to C's typeof, we need to remove
+ * references from the result [1]. Also ensure HAVE_TYPEOF is set so that
+ * typeof-dependent code is always enabled in C++ mode.
+ *
+ * [1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2927.htm#existing-decltype
+ */
+#if defined(__cplusplus)
+#ifdef pg_cxx_typeof
+#define typeof(x) pg_cxx_typeof(x)
+#elif !defined(HAVE_CXX_TYPEOF)
+#define typeof(x) std::remove_reference_t<decltype(x)>
+#endif
+#ifndef HAVE_TYPEOF
+#define HAVE_TYPEOF 1
+#endif
+#endif
+
/*
* CppAsString
* Convert the argument to a string, using the C preprocessor.
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 3824a5571bb..0059408569d 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -454,6 +454,10 @@
/* Define to 1 if your compiler understands `typeof' or something similar. */
#undef HAVE_TYPEOF
+/* Define to 1 if your C++ compiler understands `typeof' or something similar.
+ */
+#undef HAVE_CXX_TYPEOF
+
/* Define to 1 if you have the <uchar.h> header file. */
#undef HAVE_UCHAR_H
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 8c2eabcca43..5e6c8f85f6f 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -37,6 +37,7 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
RangeTblRef *node = makeNode(RangeTblRef);
+ RangeTblRef *copy = copyObject(node);
List *list = list_make1(node);
foreach_ptr(RangeTblRef, rtr, list)
@@ -54,6 +55,7 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
list_free(list);
pfree(node);
+ pfree(copy);
PG_RETURN_INT32(a + b);
}
base-commit: ba401828c194c17031a6a2dedd97bc0defd80d4b
--
2.53.0
v9-0002-Use-typeof-everywhere-instead-of-compiler-specifi.patch (text/x-patch, 2.3K) download
From c0537483fbdace6967df3aa1b76f1db6c66a5883 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v9 2/3] Use typeof everywhere instead of compiler specific
spellings
We define typeof ourselves as __typeof__ if it does not exist. So let's
actually use that for consistency. The meson/autoconf checks for
__builtin_types_compatible_p still use __typeof__ though, because there
we have not redefined it.
---
src/include/c.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index c3b3e9eea4e..07e931a6c89 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -1008,10 +1008,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define StaticAssertVariableIsOfType(varname, typename) \
- StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertDecl(__builtin_types_compatible_p(typeof(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(typeof(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define StaticAssertVariableIsOfType(varname, typename) \
@@ -1275,11 +1275,11 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock;
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
--
2.53.0
v9-0003-Make-unconstify-and-unvolatize-use-StaticAssertVa.patch (text/x-patch, 1.7K) download
From 37021f7b2cae580ca348c8600f9644f928b48232 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Thu, 19 Feb 2026 23:55:43 +0100
Subject: [PATCH v9 3/3] Make unconstify and unvolatize use
StaticAssertVariableIsOfTypeMacro
The unconstify and unvolatize macros had an almost identical assertion
as was already defined in StaticAssertVariableIsOfTypeMacro, only it had
a less useful error message and didn't have a sizeof fallback.
---
src/include/c.h | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index 07e931a6c89..5fa366914d8 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -1273,20 +1273,13 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock;
#if defined(__cplusplus)
#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
-#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
+#else
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), const underlying_type), \
- "wrong cast"), \
+ (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), volatile underlying_type), \
- "wrong cast"), \
+ (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \
(underlying_type) (expr))
-#else
-#define unconstify(underlying_type, expr) \
- ((underlying_type) (expr))
-#define unvolatize(underlying_type, expr) \
- ((underlying_type) (expr))
#endif
/*
--
2.53.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-02-27 16:40 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:52 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-02 10:56 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 2 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-02-27 16:40 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Fri Feb 20, 2026 at 10:47 AM CET, Jelte Fennema-Nio wrote:
> Makes total sense, I didn't realise decltype and typeof were not quite
> the same thing. Attached is an updated patchset that does that.
Same patchset as before, but now also including a C++ fallback for
__builtin_types_compatible_p.
Attachments: download all (4 files, .tar.gz)
v10-0001-Support-using-copyObject-in-C.patch (text/x-patch, 7.6K) download
From 077bb1a951c4eb6d61ba2e977c6b09d8d295831a 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 v10 1/4] Support using copyObject in C++
Calling copyObject in C++ without GNU extensions (e.g. then using
-std=c++11 instead of -std=gnu++11) fails with an error like this:
error: use of undeclared identifier 'typeof'; did you mean 'typeid'
This is due to the C compiler used to compile postgres supporting
typeof, but that function actually not being present in the C++
compiler. This fixes that by explicitely checking for typeof support in
C++ and then either use that, or define typeof ourselves as:
std::remove_reference_t<decltype(x)>
According to the paper that led to adding typeof to the C standard,
that's the C++ equivalent of the C typeof:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2927.htm#existing-decltype
---
config/c-compiler.m4 | 29 ++++++++++
configure | 54 +++++++++++++++++++
configure.ac | 1 +
meson.build | 25 +++++++++
src/include/c.h | 21 ++++++++
src/include/pg_config.h.in | 4 ++
.../test_cplusplusext/test_cplusplusext.cpp | 2 +
7 files changed, 136 insertions(+)
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 1509dbfa2ab..5b3cbc7e8e8 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -193,6 +193,35 @@ fi])# PGAC_C_TYPEOF
+# PGAC_CXX_TYPEOF
+# ----------------
+# Check if the C++ compiler understands typeof or a variant. Define
+# HAVE_CXX_TYPEOF if so, and define 'pg_cxx_typeof' to the actual key word.
+#
+AC_DEFUN([PGAC_CXX_TYPEOF],
+[AC_CACHE_CHECK(for C++ typeof, pgac_cv_cxx_typeof,
+[pgac_cv_cxx_typeof=no
+AC_LANG_PUSH(C++)
+for pgac_kw in typeof __typeof__; do
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
+[int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;])],
+[pgac_cv_cxx_typeof=$pgac_kw])
+ test "$pgac_cv_cxx_typeof" != no && break
+done
+AC_LANG_POP([])])
+if test "$pgac_cv_cxx_typeof" != no; then
+ AC_DEFINE(HAVE_CXX_TYPEOF, 1,
+ [Define to 1 if your C++ compiler understands `typeof' or something similar.])
+ if test "$pgac_cv_cxx_typeof" != typeof; then
+ AC_DEFINE_UNQUOTED(pg_cxx_typeof, $pgac_cv_cxx_typeof, [Define to how the C++ compiler spells `typeof'.])
+ fi
+fi])# PGAC_CXX_TYPEOF
+
+
+
# PGAC_C_TYPES_COMPATIBLE
# -----------------------
# Check if the C compiler understands __builtin_types_compatible_p,
diff --git a/configure b/configure
index a285a6ec3d7..604f9e0100b 100755
--- a/configure
+++ b/configure
@@ -15078,6 +15078,60 @@ _ACEOF
fi
fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ typeof" >&5
+$as_echo_n "checking for C++ typeof... " >&6; }
+if ${pgac_cv_cxx_typeof+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ pgac_cv_cxx_typeof=no
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+for pgac_kw in typeof __typeof__; do
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+int x = 0;
+$pgac_kw(x) y;
+y = x;
+return y;
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+ pgac_cv_cxx_typeof=$pgac_kw
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ test "$pgac_cv_cxx_typeof" != no && break
+done
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_cxx_typeof" >&5
+$as_echo "$pgac_cv_cxx_typeof" >&6; }
+if test "$pgac_cv_cxx_typeof" != no; then
+
+$as_echo "#define HAVE_CXX_TYPEOF 1" >>confdefs.h
+
+ if test "$pgac_cv_cxx_typeof" != typeof; then
+
+cat >>confdefs.h <<_ACEOF
+#define pg_cxx_typeof $pgac_cv_cxx_typeof
+_ACEOF
+
+ fi
+fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_types_compatible_p" >&5
$as_echo_n "checking for __builtin_types_compatible_p... " >&6; }
if ${pgac_cv__types_compatible+:} false; then :
diff --git a/configure.ac b/configure.ac
index 476a76c7991..93ecf41447b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1732,6 +1732,7 @@ PGAC_PRINTF_ARCHETYPE
PGAC_CXX_PRINTF_ARCHETYPE
PGAC_C_STATEMENT_EXPRESSIONS
PGAC_C_TYPEOF
+PGAC_CXX_TYPEOF
PGAC_C_TYPES_COMPATIBLE
PGAC_C_BUILTIN_CONSTANT_P
PGAC_C_BUILTIN_OP_OVERFLOW
diff --git a/meson.build b/meson.build
index 5122706477d..9cc95f0be5f 100644
--- a/meson.build
+++ b/meson.build
@@ -2953,6 +2953,31 @@ int main(void)
endif
endforeach
+# Check if the C++ compiler understands typeof or a variant.
+if have_cxx
+ foreach kw : ['typeof', '__typeof__']
+ if cxx.compiles('''
+int main(void)
+{
+ int x = 0;
+ @0@(x) y;
+ y = x;
+ return y;
+}
+'''.format(kw),
+ name: 'C++ ' + kw,
+ args: test_c_args, include_directories: postgres_inc)
+
+ cdata.set('HAVE_CXX_TYPEOF', 1)
+ if kw != 'typeof'
+ cdata.set('pg_cxx_typeof', kw)
+ endif
+
+ break
+ endif
+ endforeach
+endif
+
# MSVC doesn't cope well with defining restrict to __restrict, the
# spelling it understands, because it conflicts with
diff --git a/src/include/c.h b/src/include/c.h
index fb0ea1bc680..a4fee84398d 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -424,6 +424,27 @@
#define unlikely(x) ((x) != 0)
#endif
+/*
+ * Provide typeof in C++ for C++ compilers that don't support typeof natively.
+ * It might be spelled __typeof__ instead of typeof, in which case
+ * pg_cxx_typeof provides that mapping. If neither is supported, we can use
+ * decltype, but to make it equivalent to C's typeof, we need to remove
+ * references from the result [1]. Also ensure HAVE_TYPEOF is set so that
+ * typeof-dependent code is always enabled in C++ mode.
+ *
+ * [1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2927.htm#existing-decltype
+ */
+#if defined(__cplusplus)
+#ifdef pg_cxx_typeof
+#define typeof(x) pg_cxx_typeof(x)
+#elif !defined(HAVE_CXX_TYPEOF)
+#define typeof(x) std::remove_reference_t<decltype(x)>
+#endif
+#ifndef HAVE_TYPEOF
+#define HAVE_TYPEOF 1
+#endif
+#endif
+
/*
* CppAsString
* Convert the argument to a string, using the C preprocessor.
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index a0bd84376e7..a970577ae3e 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -451,6 +451,10 @@
/* Define to 1 if your compiler understands `typeof' or something similar. */
#undef HAVE_TYPEOF
+/* Define to 1 if your C++ compiler understands `typeof' or something similar.
+ */
+#undef HAVE_CXX_TYPEOF
+
/* Define to 1 if you have the <uchar.h> header file. */
#undef HAVE_UCHAR_H
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index eb129dd15d4..ea04a761184 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -37,6 +37,7 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
RangeTblRef *node = makeNode(RangeTblRef);
+ RangeTblRef *copy = copyObject(node);
List *list = list_make1(node);
foreach_ptr(RangeTblRef, rtr, list)
@@ -54,6 +55,7 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
list_free(list);
pfree(node);
+ pfree(copy);
switch (a)
{
base-commit: 284925508ae685a63ee056f89a336caecab64a63
--
2.53.0
v10-0002-Use-typeof-everywhere-instead-of-compiler-specif.patch (text/x-patch, 2.3K) download
From c8fd6666836c7696c49708e1afb785cad3b55f13 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 8 Dec 2025 08:13:51 +0100
Subject: [PATCH v10 2/4] Use typeof everywhere instead of compiler specific
spellings
We define typeof ourselves as __typeof__ if it does not exist. So let's
actually use that for consistency. The meson/autoconf checks for
__builtin_types_compatible_p still use __typeof__ though, because there
we have not redefined it.
---
src/include/c.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index a4fee84398d..df01acdf6ba 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -1008,10 +1008,10 @@ pg_noreturn extern void ExceptionalCondition(const char *conditionName,
*/
#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
#define StaticAssertVariableIsOfType(varname, typename) \
- StaticAssertDecl(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ StaticAssertDecl(__builtin_types_compatible_p(typeof(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))
#define StaticAssertVariableIsOfTypeMacro(varname, typename) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+ (StaticAssertExpr(__builtin_types_compatible_p(typeof(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define StaticAssertVariableIsOfType(varname, typename) \
@@ -1275,11 +1275,11 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock;
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), const underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), const underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(__typeof(expr), volatile underlying_type), \
+ (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), volatile underlying_type), \
"wrong cast"), \
(underlying_type) (expr))
#else
--
2.53.0
v10-0003-Make-unconstify-and-unvolatize-use-StaticAssertV.patch (text/x-patch, 1.7K) download
From 8abacdb5305619a19fb3dc7eaa53d4cc4d7d805e Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Thu, 19 Feb 2026 23:55:43 +0100
Subject: [PATCH v10 3/4] Make unconstify and unvolatize use
StaticAssertVariableIsOfTypeMacro
The unconstify and unvolatize macros had an almost identical assertion
as was already defined in StaticAssertVariableIsOfTypeMacro, only it had
a less useful error message and didn't have a sizeof fallback.
---
src/include/c.h | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/include/c.h b/src/include/c.h
index df01acdf6ba..c92b214f6b0 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -1273,20 +1273,13 @@ typedef struct PGAlignedXLogBlock PGAlignedXLogBlock;
#if defined(__cplusplus)
#define unconstify(underlying_type, expr) const_cast<underlying_type>(expr)
#define unvolatize(underlying_type, expr) const_cast<underlying_type>(expr)
-#elif defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
+#else
#define unconstify(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), const underlying_type), \
- "wrong cast"), \
+ (StaticAssertVariableIsOfTypeMacro(expr, const underlying_type), \
(underlying_type) (expr))
#define unvolatize(underlying_type, expr) \
- (StaticAssertExpr(__builtin_types_compatible_p(typeof(expr), volatile underlying_type), \
- "wrong cast"), \
+ (StaticAssertVariableIsOfTypeMacro(expr, volatile underlying_type), \
(underlying_type) (expr))
-#else
-#define unconstify(underlying_type, expr) \
- ((underlying_type) (expr))
-#define unvolatize(underlying_type, expr) \
- ((underlying_type) (expr))
#endif
/*
--
2.53.0
v10-0004-Add-C-version-of-__builtin_types_compatible_p.patch (text/x-patch, 3.7K) download
From 437a8aece153c5dc24c0e2708c034fe1718ea3bf Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Fri, 13 Feb 2026 09:39:34 +0100
Subject: [PATCH v10 4/4] Add C++ version of __builtin_types_compatible_p
StaticAssertVariableIsOfType would fail to compile in C++ extensions if
meson/autoconf has detected HAVE__BUILTIN_TYPES_COMPATIBLE_P to be true
for the C compiler. Basically equivalent to the PG_PRINTF_ATTRIBUTE
situation in 0909380e4c9.
This fixes that problem by defining __builtin_types_compatible_p in C++
using an equivalent STL constructs.
---
src/include/c.h | 22 +++++++++++++++++++
.../test_cplusplusext/test_cplusplusext.cpp | 20 ++++++++++++++++-
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/src/include/c.h b/src/include/c.h
index c92b214f6b0..ba629a3503b 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -80,6 +80,12 @@
#ifdef HAVE_XLOCALE_H
#include <xlocale.h>
#endif
+#ifdef __cplusplus
+extern "C++"
+{
+#include <type_traits>
+}
+#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
@@ -443,7 +449,23 @@
#ifndef HAVE_TYPEOF
#define HAVE_TYPEOF 1
#endif
+/*
+ * Provide __builtin_types_compatible_p for C++ by comparing types with
+ * std::is_same after stripping cv-qualifiers. The second branch handles
+ * GCC's special case where an incomplete array (e.g. int[]) is considered
+ * compatible with a complete array of the same element type (e.g. int[3]).
+ */
+#define __builtin_types_compatible_p(x, y) \
+ (std::is_same<std::remove_cv_t<x>, std::remove_cv_t<y>>::value || \
+ (std::is_array<x>::value && std::is_array<y>::value && \
+ (std::extent<x>::value == 0 || std::extent<y>::value == 0) && \
+ std::is_same<std::remove_cv_t<std::remove_extent_t<x>>, \
+ std::remove_cv_t<std::remove_extent_t<y>>>::value))
+#ifndef HAVE__BUILTIN_TYPES_COMPATIBLE_P
+#define HAVE__BUILTIN_TYPES_COMPATIBLE_P 1
#endif
+#endif
+
/*
* CppAsString
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index ea04a761184..936ca422c76 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -34,11 +34,14 @@ StaticAssertDecl(sizeof(int32) == 4, "int32 should be 4 bytes");
extern "C" Datum
test_cplusplus_add(PG_FUNCTION_ARGS)
{
- int32 a = PG_GETARG_INT32(0);
+ const int32 a = PG_GETARG_INT32(0);
int32 b = PG_GETARG_INT32(1);
+ const char *p = "";
RangeTblRef *node = makeNode(RangeTblRef);
RangeTblRef *copy = copyObject(node);
List *list = list_make1(node);
+ const int32 int_array[3] = {0};
+ extern int32 incomplete_array[];
foreach_ptr(RangeTblRef, rtr, list)
{
@@ -52,6 +55,21 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
(void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
+ StaticAssertVariableIsOfType(a, int32);
+ StaticAssertVariableIsOfType(a, const int32);
+ StaticAssertVariableIsOfType(b, const int32);
+ StaticAssertVariableIsOfType(int_array, int32[3]);
+ StaticAssertVariableIsOfType(int_array, const int32[3]);
+ StaticAssertVariableIsOfType(p, const char *);
+ StaticAssertVariableIsOfTypeMacro(a, int32);
+ StaticAssertVariableIsOfTypeMacro(a, const int32);
+ StaticAssertVariableIsOfTypeMacro(b, int32);
+ StaticAssertVariableIsOfTypeMacro(int_array, int32[3]);
+ StaticAssertVariableIsOfTypeMacro(int_array, const int32[3]);
+ StaticAssertVariableIsOfTypeMacro(p, const char *);
+ /* incomplete array matches complete array type */
+ StaticAssertVariableIsOfType(incomplete_array, int32[3]);
+ StaticAssertVariableIsOfTypeMacro(incomplete_array, int32[3]);
list_free(list);
pfree(node);
--
2.53.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-02-27 16:52 ` Peter Eisentraut <peter@eisentraut.org>
2026-02-28 11:31 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-02-27 16:52 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 27.02.26 17:40, Jelte Fennema-Nio wrote:
> On Fri Feb 20, 2026 at 10:47 AM CET, Jelte Fennema-Nio wrote:
>> Makes total sense, I didn't realise decltype and typeof were not quite
>> the same thing. Attached is an updated patchset that does that.
>
> Same patchset as before, but now also including a C++ fallback for
> __builtin_types_compatible_p.
Have you tested whether/how these configure/meson tests work if no C++
compiler is found?
(I haven't, I'm just wondering.)
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:52 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-02-28 11:31 ` Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-02-28 11:31 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Fri, 27 Feb 2026 at 17:52, Peter Eisentraut <peter@eisentraut.org> wrote:
> Have you tested whether/how these configure/meson tests work if no C++
> compiler is found?
>
> (I haven't, I'm just wondering.)
I hadn't before, but done now. It compiles postgres without problems
(but without the cplusplusext extension ofcourse). For meson the new
meson checks are inside have_cxx, so they are not run at all. For
configure the checks are run, but they detect typeof as not available
in C++ (because its unable to compile the test program).
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-03-02 10:56 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-06 09:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
1 sibling, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-03-02 10:56 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 27.02.26 17:40, Jelte Fennema-Nio wrote:
> On Fri Feb 20, 2026 at 10:47 AM CET, Jelte Fennema-Nio wrote:
>> Makes total sense, I didn't realise decltype and typeof were not quite
>> the same thing. Attached is an updated patchset that does that.
>
> Same patchset as before, but now also including a C++ fallback for
> __builtin_types_compatible_p.
I have committed v10-0001. Now let's give the buildfarm a few days.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-02 10:56 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-06 09:23 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-09 08:39 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-03-06 09:23 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 02.03.26 11:56, Peter Eisentraut wrote:
> On 27.02.26 17:40, Jelte Fennema-Nio wrote:
>> On Fri Feb 20, 2026 at 10:47 AM CET, Jelte Fennema-Nio wrote:
>>> Makes total sense, I didn't realise decltype and typeof were not quite
>>> the same thing. Attached is an updated patchset that does that.
>>
>> Same patchset as before, but now also including a C++ fallback for
>> __builtin_types_compatible_p.
>
> I have committed v10-0001. Now let's give the buildfarm a few days.
I have committed v10-0002 and v10-0003 now. I will look at the
remaining patch in a few days.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-02 10:56 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-06 09:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-09 08:39 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-13 09:08 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-03-09 08:39 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 06.03.26 10:23, Peter Eisentraut wrote:
> On 02.03.26 11:56, Peter Eisentraut wrote:
>> On 27.02.26 17:40, Jelte Fennema-Nio wrote:
>>> On Fri Feb 20, 2026 at 10:47 AM CET, Jelte Fennema-Nio wrote:
>>>> Makes total sense, I didn't realise decltype and typeof were not quite
>>>> the same thing. Attached is an updated patchset that does that.
>>>
>>> Same patchset as before, but now also including a C++ fallback for
>>> __builtin_types_compatible_p.
>>
>> I have committed v10-0001. Now let's give the buildfarm a few days.
>
> I have committed v10-0002 and v10-0003 now. I will look at the
> remaining patch in a few days.
Thoughts on v10-0004:
It's not clear to me to what extent StaticAssertVariableIsOfType would
be useful in C++. There are two general areas where it is used. One,
when multiple separate extensions want to talk to each other, to check
the types of certain entry point variables, such as
plpython/hstore_plpython. And two, in some macro-based template
libraries such as lib/ilist.h and lib/pairingheap.h. You add a lot of
tests, but do they cover these particular use scenarios?
In either case, it might be better to create a test on that level and
then see what we'd need to make happen to have it working under C++.
There is lots of trickery involved there, so it's not clear whether it
works out of the box in C++ already.
Are there any of these that you are particularly interested in for your
work?
About the specific implementation, I'm hesitant to build this on top of
__builtin_types_compatible_p(). Aside from the ugliness of redefining a
symbol that starts with __builtin_*, I think we should really work to
get rid of __builtin_types_compatible_p() and replace it with _Generic,
which would be portable beyond GCC.
How about we make a pg_types_compatible_p(), which would look like this:
#if defined(__cplusplus)
// your C++ code here
#else if defined(HAVE__GENERIC)
// C code using _Generic here
#else
// C code using __builtin_types_compatible_p here
#endif
We can require that a supported C compiler must support either _Generic
or __builtin_types_compatible_p, so we don't need any further fallback.
(So we could remove the configure test of __builtin_types_compatible_p,
but we'd add one for _Generic.) And in a few years we could even remove
the __builtin_types_compatible_p fallback.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-19 08:31 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-02 10:56 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-06 09:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-09 08:39 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-13 09:08 ` Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-03-13 09:08 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Mon, 9 Mar 2026 at 09:39, Peter Eisentraut <peter@eisentraut.org> wrote:
> I think we should really work to
> get rid of __builtin_types_compatible_p() and replace it with _Generic,
> which would be portable beyond GCC.
I initially intended to do this, but sadly using _Generic inside our
static assert constructs (even the new version you added) causes
internal compiler errors on MSVC 19... I agree with your other
feedback, and I think it's probably best to retract this patch (I've
marked it as committeed in the commitfest now, because of all the
other patches). The main reason I cared about this was to have a
_Generic based macro for type comparisons, which I could use in other
patches. I'll just create some there instead.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-03-23 09:27 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-03-23 09:27 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On 13.02.26 11:28, Jelte Fennema-Nio wrote:
> After discussing the topic in-person with Peter at FOSDEM. We agreed
> that the best road forward was to not bother with MSVC for now. No-one
> has actually expressed an interest in being able to build C++ extension
> using MSVC, and the effort to support it is both non-trivial and not
> without downsides to the rest of the codebase. We can always come back
> to this later, possibly requiring C++20 on MSVC.
I checked what would currently be missing to get MSVC supported.
Attached is the patch.
I think we should commit the pg_list.h changes, since the C-style
compound literals are not a C++ feature at all, and so without this MSVC
would never get supported. (Or you couldn't use PostgreSQL lists, which
would be very limiting.)
Here is a Compiler Explorer link that I used to check that the generated
code doesn't change: https://godbolt.org/z/ovKKzEfs6
The other changes deal with designated initializers and flexible array
members. These are not a blocker, since extension authors could deal
with them themselves by adding appropriate compiler options or similar.
Attachments:
nocfbot-0001-Try-test_cplusplusext-with-MSVC.patch (text/plain, 3.6K) download
From bf1a3fb2cee222a26660c1266089a4c94147c0cb Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 23 Mar 2026 10:15:04 +0100
Subject: [PATCH] Try test_cplusplusext with MSVC
- Compound literals, as used in pg_list.h, are not a C++ feature.
MSVC doesn't accept these. (GCC and Clang accept them, but they would
warn in -pedantic mode.) Replace with inline functions. (This is the
only instance of a compound literal used in PostgreSQL header files.)
- Flexible array members, as used in many PostgreSQL header files, are
not a C++ feature. MSVC warns about these. Disable the
warning. (GCC and Clang accept them, but they would warn in -pedantic
mode.)
- Designated initializers, as used in PG_MODULE_MAGIC, require C++20.
ci-os-only: windows
---
src/include/nodes/pg_list.h | 41 +++++++++++++++++--
.../modules/test_cplusplusext/meson.build | 12 +++---
.../test_cplusplusext/test_cplusplusext.cpp | 8 ++++
3 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h
index ae80975548f..09b84aa0933 100644
--- a/src/include/nodes/pg_list.h
+++ b/src/include/nodes/pg_list.h
@@ -204,10 +204,43 @@ list_length(const List *l)
/*
* Convenience macros for building fixed-length lists
*/
-#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
-#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
-#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
-#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
+
+static inline ListCell
+list_make_ptr_cell(void *v)
+{
+ ListCell c;
+
+ c.ptr_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_int_cell(int v)
+{
+ ListCell c;
+
+ c.int_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_oid_cell(Oid v)
+{
+ ListCell c;
+
+ c.oid_value = v;
+ return c;
+}
+
+static inline ListCell
+list_make_xid_cell(TransactionId v)
+{
+ ListCell c;
+
+ c.xid_value = v;
+ return c;
+}
+#endif
#define list_make1(x1) \
list_make1_impl(T_List, list_make_ptr_cell(x1))
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..34f54cf1335 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -4,11 +4,6 @@ if not have_cxx
subdir_done()
endif
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
- subdir_done()
-endif
-
test_cplusplusext_sources = files(
'test_cplusplusext.cpp',
)
@@ -21,8 +16,11 @@ endif
test_cplusplusext = shared_module('test_cplusplusext',
test_cplusplusext_sources,
- kwargs: pg_test_mod_args,
-)
+ kwargs: pg_test_mod_args + {
+ # C++20 is required for designated initializers in PG_MODULE_MAGIC.
+ 'cpp_args': pg_test_mod_args['cpp_args'] + (cxx.get_id() == 'msvc' ? ['/std:c++20'] : []),
+ },
+ )
test_install_libs += test_cplusplusext
test_install_data += files(
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 93cd7dd07f7..8381bef412a 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -14,6 +14,14 @@
* -------------------------------------------------------------------------
*/
+/*
+ * The warning "nonstandard extension used: zero-sized array in
+ * struct/union" appears for many PostgreSQL header files.
+ */
+#ifdef _MSC_VER
+#pragma warning(disable : 4200)
+#endif
+
extern "C" {
#include "postgres.h"
#include "fmgr.h"
--
2.53.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-23 09:58 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-03-23 09:58 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On Mon, 23 Mar 2026 at 10:27, Peter Eisentraut <peter@eisentraut.org> wrote:
> I think we should commit the pg_list.h changes, since the C-style
> compound literals are not a C++ feature at all, and so without this MSVC
> would never get supported. (Or you couldn't use PostgreSQL lists, which
> would be very limiting.)
Sounds good to me.
> The other changes deal with designated initializers and flexible array
> members. These are not a blocker, since extension authors could deal
> with them themselves by adding appropriate compiler options or similar.
I think we should add these flags to CXXFLAGS for MSVC by default,
similar to how we add -std=gnu++11/-std=c++11 for other compilers. We
can then document on the C++ extension docs page, that MSVC compilers
require C++20 support.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-03-27 11:23 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-03-27 11:23 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On 23.03.26 10:58, Jelte Fennema-Nio wrote:
> On Mon, 23 Mar 2026 at 10:27, Peter Eisentraut <peter@eisentraut.org> wrote:
>> I think we should commit the pg_list.h changes, since the C-style
>> compound literals are not a C++ feature at all, and so without this MSVC
>> would never get supported. (Or you couldn't use PostgreSQL lists, which
>> would be very limiting.)
>
> Sounds good to me.
This has been committed.
>> The other changes deal with designated initializers and flexible array
>> members. These are not a blocker, since extension authors could deal
>> with them themselves by adding appropriate compiler options or similar.
>
> I think we should add these flags to CXXFLAGS for MSVC by default,
> similar to how we add -std=gnu++11/-std=c++11 for other compilers. We
> can then document on the C++ extension docs page, that MSVC compilers
> require C++20 support.
Here is another tidied up patch set for this. I didn't go quite as far
as enabling C++20 by default in meson.build, this would just take more
time to work out and test all the different combinations, but I added
the flag to the Cirrus CI task, since there we know what compiler we have.
Attachments: download all (3 files, .tar.gz)
v11-0001-meson-Make-room-for-C-only-warning-flags-for-MSV.patch (text/plain, 2.2K) download
From a9f04ed6fd4ce8ea5b01cbafec2181a2d69a2783 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 27 Mar 2026 11:45:36 +0100
Subject: [PATCH v11 1/3] meson: Make room for C++-only warning flags for MSVC
Refactor the MSVC warning option handling to have a list of common
flags and lists of flags specific to C and C++.
---
meson.build | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/meson.build b/meson.build
index ea31cbce9c0..42b0a9a6a71 100644
--- a/meson.build
+++ b/meson.build
@@ -2293,27 +2293,42 @@ endforeach
if cc.get_id() == 'msvc'
- cflags_warn += [
+ msvc_common_warning_flags = [
+ # Disable warnings in system headers
+ '/external:anglebrackets',
+ '/external:W0',
+
# Warnings to disable:
- # from /W1:
- '/wd4090', # different 'modifier' qualifiers
# from /W2:
'/wd4244', # conversion from 'type1' to 'type2', possible loss of data
+
+ # Additional warnings to enable:
+ '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled [like -Wswitch]
+ '/w24102', # unreferenced label [like -Wunused-label]
+ ]
+
+ msvc_c_warning_flags = [
+ # Warnings to disable:
+ # from /W1:
+ '/wd4090', # different 'modifier' qualifiers
# from /W3:
'/wd4018', # signed/unsigned mismatch
'/wd4101', # unreferenced local variable [like -Wunused-variable, but there is no "unused" attribute, so too noisy]
'/wd4267', # conversion from 'size_t' to 'type', possible loss of data
# Additional warnings to enable:
- '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled [like -Wswitch]
- '/w24102', # unreferenced label [like -Wunused-label]
'/w24255', # 'function' : no function prototype given: converting '()' to '(void)' [like -Wstrict-prototypes]
+ ]
- # Disable warnings in system headers
- '/external:anglebrackets',
- '/external:W0',
+ msvc_cxx_warning_flags = [
]
+ cflags_warn += msvc_common_warning_flags
+ cflags_warn += msvc_c_warning_flags
+
+ cxxflags_warn += msvc_common_warning_flags
+ cxxflags_warn += msvc_cxx_warning_flags
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
--
2.53.0
v11-0002-Disable-some-C-warnings-in-MSVC.patch (text/plain, 900B) download
From 543f49124a45804584c193d4083bebe3bab74f71 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 26 Mar 2026 08:35:45 +0100
Subject: [PATCH v11 2/3] Disable some C++ warnings in MSVC
Flexible array members, as used in many PostgreSQL header files, are
not a C++ feature. MSVC warns about these. Disable the
warning. (GCC and Clang accept them, but they would warn in -pedantic
mode.)
---
meson.build | 3 +++
1 file changed, 3 insertions(+)
diff --git a/meson.build b/meson.build
index 42b0a9a6a71..64a5bb888d6 100644
--- a/meson.build
+++ b/meson.build
@@ -2321,6 +2321,9 @@ if cc.get_id() == 'msvc'
]
msvc_cxx_warning_flags = [
+ # Warnings to disable:
+ # from /W2:
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union [widely used in PostgreSQL C headers]
]
cflags_warn += msvc_common_warning_flags
--
2.53.0
v11-0003-Enable-test_cplusplusext-with-MSVC.patch (text/plain, 3.6K) download
From ca2797018cca5b705d55456dcaca6d18db4816e4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 27 Mar 2026 11:49:33 +0100
Subject: [PATCH v11 3/3] Enable test_cplusplusext with MSVC
The test_cplusplusext test module has so far been disabled on MSVC.
The only remaining problem now is that designated initializers, as
used in PG_MODULE_MAGIC, require C++20. (With GCC and Clang they work
in older C++ versions as well.)
This adds another test in the top-level meson.build to check that the
compiler is in C++20 mode. This is not required, we are just checking
and recording the answer. If yes and we are using MSVC, we can enable
the test module. (With other compilers it's already always enabled
and stays that way.)
Most current compilers likely won't be in C++20 mode by default. This
doesn't change that; we are not doing anything to try to switch the
compiler into that mode. This might be a separate project, but for
now we'll leave that for the user or the test scaffolding.
The VS task on Cirrus CI is changed to provide the required flag to
turn on C++20 mode.
---
.cirrus.tasks.yml | 1 +
meson.build | 35 ++++++++++++-------
.../modules/test_cplusplusext/meson.build | 6 ++--
3 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 0f32827952f..a22cef063f3 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -782,6 +782,7 @@ task:
CIRRUS_WINDOWS_ERROR_MODE: 0x8001
MESON_FEATURES:
+ -Dcpp_args=/std:c++20
-Dauto_features=disabled
-Dldap=enabled
-Dssl=openssl
diff --git a/meson.build b/meson.build
index 64a5bb888d6..d9dffa19141 100644
--- a/meson.build
+++ b/meson.build
@@ -654,23 +654,32 @@ cxx11_test = '''
#endif
'''
-if have_cxx and not cxx.compiles(cxx11_test, name: 'C++11')
- cxx11_ok = false
- if cxx.get_id() == 'msvc'
- cxx11_test_args = ['/std:c++14'] # oldest version supported
- else
- cxx11_test_args = ['-std=gnu++11', '-std=c++11']
- endif
- foreach arg : cxx11_test_args
- if cxx.compiles(cxx11_test, name: 'C++11 with @0@'.format(arg), args: [arg])
- cxx11_ok = true
- cxxflags += arg
- break
+cxx20_test = '''
+#if !defined __cplusplus || __cplusplus < 202002L
+# error "Compiler does not advertise C++20 conformance"
+#endif
+'''
+
+if have_cxx
+ cxx11_ok = cxx.compiles(cxx11_test, name: 'C++11')
+ if not cxx11_ok
+ if cxx.get_id() == 'msvc'
+ cxx11_test_args = ['/std:c++14'] # oldest version supported
+ else
+ cxx11_test_args = ['-std=gnu++11', '-std=c++11']
endif
- endforeach
+ foreach arg : cxx11_test_args
+ if cxx.compiles(cxx11_test, name: 'C++11 with @0@'.format(arg), args: [arg])
+ cxx11_ok = true
+ cxxflags += arg
+ break
+ endif
+ endforeach
+ endif
if not cxx11_ok
error('C++ compiler does not support C++11')
endif
+ cxx20_ok = cxx.compiles(cxx20_test, name: 'C++20')
endif
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..a9b294d6b1c 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -4,8 +4,10 @@ if not have_cxx
subdir_done()
endif
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
+# Test extension requires C++20 support (for designated initializers
+# in PG_MODULE_MAGIC). Compilers other than MSVC are ok in practice,
+# though.
+if cc.get_id() == 'msvc' and not cxx20_ok
subdir_done()
endif
--
2.53.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-29 22:53 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-03-29 22:53 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On Fri, 27 Mar 2026 at 12:23, Peter Eisentraut <peter@eisentraut.org> wrote:
> Here is another tidied up patch set for this. I didn't go quite as far
> as enabling C++20 by default in meson.build, this would just take more
> time to work out and test all the different combinations, but I added
> the flag to the Cirrus CI task, since there we know what compiler we have.
I think 0001 and 0002 are good.
0003 seems awkward though. Attached is an approach that I think is
better: It actually checks for the required featureset and adds the
necessary flags to the compiler.
I also added a small patch in 0004 to align configure and meson
behaviour when no sufficiently modern compiler is found.
Attachments: download all (4 files, .tar.gz)
v12-0001-meson-Make-room-for-C-only-warning-flags-for-MSV.patch (text/x-patch, 2.3K) download
From 6b04f2bc87231998946ff0736013a98c9f23df2c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Fri, 27 Mar 2026 11:45:36 +0100
Subject: [PATCH v12 1/4] meson: Make room for C++-only warning flags for MSVC
Refactor the MSVC warning option handling to have a list of common
flags and lists of flags specific to C and C++.
---
meson.build | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/meson.build b/meson.build
index ea31cbce9c0..42b0a9a6a71 100644
--- a/meson.build
+++ b/meson.build
@@ -2293,27 +2293,42 @@ endforeach
if cc.get_id() == 'msvc'
- cflags_warn += [
+ msvc_common_warning_flags = [
+ # Disable warnings in system headers
+ '/external:anglebrackets',
+ '/external:W0',
+
# Warnings to disable:
- # from /W1:
- '/wd4090', # different 'modifier' qualifiers
# from /W2:
'/wd4244', # conversion from 'type1' to 'type2', possible loss of data
+
+ # Additional warnings to enable:
+ '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled [like -Wswitch]
+ '/w24102', # unreferenced label [like -Wunused-label]
+ ]
+
+ msvc_c_warning_flags = [
+ # Warnings to disable:
+ # from /W1:
+ '/wd4090', # different 'modifier' qualifiers
# from /W3:
'/wd4018', # signed/unsigned mismatch
'/wd4101', # unreferenced local variable [like -Wunused-variable, but there is no "unused" attribute, so too noisy]
'/wd4267', # conversion from 'size_t' to 'type', possible loss of data
# Additional warnings to enable:
- '/w24062', # enumerator 'identifier' in switch of enum 'enumeration' is not handled [like -Wswitch]
- '/w24102', # unreferenced label [like -Wunused-label]
'/w24255', # 'function' : no function prototype given: converting '()' to '(void)' [like -Wstrict-prototypes]
+ ]
- # Disable warnings in system headers
- '/external:anglebrackets',
- '/external:W0',
+ msvc_cxx_warning_flags = [
]
+ cflags_warn += msvc_common_warning_flags
+ cflags_warn += msvc_c_warning_flags
+
+ cxxflags_warn += msvc_common_warning_flags
+ cxxflags_warn += msvc_cxx_warning_flags
+
cppflags += [
'/DWIN32',
'/DWINDOWS',
base-commit: 10e4d8aaf46fb46b8b78e026560b68af84a6495b
--
2.53.0
v12-0002-Disable-some-C-warnings-in-MSVC.patch (text/x-patch, 900B) download
From 366dfbc11fd047f75107a87023b39a58fa7a2326 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 26 Mar 2026 08:35:45 +0100
Subject: [PATCH v12 2/4] Disable some C++ warnings in MSVC
Flexible array members, as used in many PostgreSQL header files, are
not a C++ feature. MSVC warns about these. Disable the
warning. (GCC and Clang accept them, but they would warn in -pedantic
mode.)
---
meson.build | 3 +++
1 file changed, 3 insertions(+)
diff --git a/meson.build b/meson.build
index 42b0a9a6a71..64a5bb888d6 100644
--- a/meson.build
+++ b/meson.build
@@ -2321,6 +2321,9 @@ if cc.get_id() == 'msvc'
]
msvc_cxx_warning_flags = [
+ # Warnings to disable:
+ # from /W2:
+ '/wd4200', # nonstandard extension used: zero-sized array in struct/union [widely used in PostgreSQL C headers]
]
cflags_warn += msvc_common_warning_flags
--
2.53.0
v12-0003-Add-support-for-C-extensions-with-MSVC.patch (text/x-patch, 5.7K) download
From df6d9e8d1bb955d9cffe3095cc27d4209de1ce33 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sun, 29 Mar 2026 13:01:37 +0200
Subject: [PATCH v12 3/4] Add support for C++ extensions with MSVC
To build C++ extensions we need support for designated initializers,
because PG_MODULE_MAGIC uses it. Designated initializers only got
standardized in C++20. In GCC and Clang they also work when using
earlier C++ versions, but MSVC really only supports them when its
configured to be in C++20 mode or higher.
This extends C++11 feature test to also check for designated initializer
support.
When passing both -pedantic and -Werror even Clang and GCC can fail this
new feature test if they're old enough that they don't compile with
C++20 by default. So this also changes meson and configure to try C++20
if using C++11 didn't work. Before this patch this such a setup would
pass the C++11 check but would then fail to compile test_cplusplusext.
---
configure.ac | 13 ++++++----
doc/src/sgml/xfunc.sgml | 5 ++++
meson.build | 26 +++++++++++--------
.../modules/test_cplusplusext/meson.build | 5 ----
4 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/configure.ac b/configure.ac
index 2baac5e9da7..e4570a805c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -398,17 +398,20 @@ AC_SUBST(have_cxx)
if test "$have_cxx" = yes; then
-# Detect option needed for C++11
-AC_MSG_CHECKING([for $CXX option to accept ISO C++11])
+# Detect option needed for C++11 with designated initializers. We need
+# designated initializers because we use them in many of our headers, including
+# in the PG_MODULE_MAGIC definition.
+AC_MSG_CHECKING([for $CXX option to accept ISO C++11 with designated initializers])
AC_CACHE_VAL([pgac_cv_prog_cxx_cxx11],
[pgac_cv_prog_cxx_cxx11=no
pgac_save_CXX=$CXX
AC_LANG_PUSH([C++])
-for pgac_arg in '' '-std=gnu++11' '-std=c++11'; do
+for pgac_arg in '' '-std=gnu++11' '-std=c++11' '-std=gnu++20' '-std=c++20'; do
CXX="$pgac_save_CXX $pgac_arg"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#if !defined __cplusplus || __cplusplus < 201103L
# error "Compiler does not advertise C++11 conformance"
-#endif]])], [[pgac_cv_prog_cxx_cxx11=$pgac_arg]])
+#endif
+struct S { int x; } s = { .x = 1 };]])], [[pgac_cv_prog_cxx_cxx11=$pgac_arg]])
test x"$pgac_cv_prog_cxx_cxx11" != x"no" && break
done
AC_LANG_POP([C++])
@@ -416,7 +419,7 @@ CXX=$pgac_save_CXX])
if test x"$pgac_cv_prog_cxx_cxx11" = x"no"; then
AC_MSG_RESULT([unsupported])
- AC_MSG_WARN([C++ compiler "$CXX" does not support C++11])
+ AC_MSG_WARN([C++ compiler "$CXX" does not support C++11 with designated initializers])
have_cxx=no
elif test x"$pgac_cv_prog_cxx_cxx11" = x""; then
AC_MSG_RESULT([none needed])
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index 70e815b8a2c..6895fe483c1 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -4026,6 +4026,11 @@ extern PgStat_Kind pgstat_register_kind(PgStat_Kind kind,
<itemizedlist>
<listitem>
+ <para>
+ You need a C++ compiler that supports C++11 and designated
+ initializers (GCC and Clang support this in C++11 mode, but MSVC only
+ supports it in C++20 mode).
+ </para>
<para>
All functions accessed by the backend must present a C interface
to the backend; these C functions can then call C++ functions.
diff --git a/meson.build b/meson.build
index 64a5bb888d6..bcad5f4fc01 100644
--- a/meson.build
+++ b/meson.build
@@ -647,29 +647,33 @@ if not cc.compiles(c11_test, name: 'C11')
endif
-# Do we need an option to enable C++11?
-cxx11_test = '''
+# Do we need an option to enable C++11 and/or designated initializers? We need
+# designated initiliazers because we use them in many of our headers, including
+# in the PG_MODULE_MAGIC definition. Clang and gcc support designated
+# initializers in C++11 mode, but MSVC only supports them in C++20 mode.
+cxx_features_test = '''
#if !defined __cplusplus || __cplusplus < 201103L
# error "Compiler does not advertise C++11 conformance"
#endif
+struct S { int x; } s = { .x = 1 };
'''
-if have_cxx and not cxx.compiles(cxx11_test, name: 'C++11')
- cxx11_ok = false
+if have_cxx and not cxx.compiles(cxx_features_test, name: 'C++11 with designated initializers')
+ cxx_features_ok = false
if cxx.get_id() == 'msvc'
- cxx11_test_args = ['/std:c++14'] # oldest version supported
+ cxx_features_test_args = ['/std:c++20']
else
- cxx11_test_args = ['-std=gnu++11', '-std=c++11']
+ cxx_features_test_args = ['-std=gnu++11', '-std=c++11', '-std=gnu++20', 'std=c++20']
endif
- foreach arg : cxx11_test_args
- if cxx.compiles(cxx11_test, name: 'C++11 with @0@'.format(arg), args: [arg])
- cxx11_ok = true
+ foreach arg : cxx_features_test_args
+ if cxx.compiles(cxx_features_test, name: 'C++11 with designated initializers with @0@'.format(arg), args: [arg])
+ cxx_features_ok = true
cxxflags += arg
break
endif
endforeach
- if not cxx11_ok
- error('C++ compiler does not support C++11')
+ if not cxx_features_ok
+ error('C++ compiler does not support C++11 with designated initializers')
endif
endif
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..24a9cf16dca 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -4,11 +4,6 @@ if not have_cxx
subdir_done()
endif
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
- subdir_done()
-endif
-
test_cplusplusext_sources = files(
'test_cplusplusext.cpp',
)
--
2.53.0
v12-0004-meson-Consider-an-insufficient-C-compiler-a-warn.patch (text/x-patch, 1005B) download
From 3eeeabc4335d2ceef777b20bb1460a38a82baf2d Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Mon, 30 Mar 2026 00:45:53 +0200
Subject: [PATCH v12 4/4] meson: Consider an insufficient C++ compiler a
warning
Meson and configure were handling the case of a C++ compiler with an
insufficient feature set differently. In configure, it would be a
warning, but meson would throw a hard error. This makes it a warning in
meson too.
---
meson.build | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index bcad5f4fc01..ef1d7ed9a57 100644
--- a/meson.build
+++ b/meson.build
@@ -673,7 +673,8 @@ if have_cxx and not cxx.compiles(cxx_features_test, name: 'C++11 with designated
endif
endforeach
if not cxx_features_ok
- error('C++ compiler does not support C++11 with designated initializers')
+ warning('C++ compiler does not support C++11 with designated initializers')
+ have_cxx = false
endif
endif
--
2.53.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-03-31 08:33 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-03-31 08:33 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On 30.03.26 00:53, Jelte Fennema-Nio wrote:
> On Fri, 27 Mar 2026 at 12:23, Peter Eisentraut <peter@eisentraut.org>
> wrote:
>> Here is another tidied up patch set for this. I didn't go quite as far
>> as enabling C++20 by default in meson.build, this would just take more
>> time to work out and test all the different combinations, but I added
>> the flag to the Cirrus CI task, since there we know what compiler we
>> have.
>
> I think 0001 and 0002 are good.
>
> 0003 seems awkward though. Attached is an approach that I think is
> better: It actually checks for the required featureset and adds the
> necessary flags to the compiler.
Hmm, note that C++ is also used for LLVM/JIT, and by requiring this
additional feature set we are also imposing new requirements for those
users. This has not been fully explored, and I hesitate to add such a
new requirement at the last moment.
But how about this: We add the feature test that you propose and enable
the extension based on that. See attached patch. This reduces to
essentially a three-line patch, much simpler than all previous proposals.
Attachments:
0001-Enable-test_cplusplusext-with-MSVC.patch (text/plain, 3.0K) download
From ec7e12b1c0e53a9a1a46d1f43479fdf71d4ba8eb Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 31 Mar 2026 09:48:52 +0200
Subject: [PATCH] Enable test_cplusplusext with MSVC
The test_cplusplusext test module has so far been disabled on MSVC.
The only remaining problem now is that designated initializers, as
used in PG_MODULE_MAGIC, require C++20. (With GCC and Clang they work
in older C++ versions as well.)
This adds another test in the top-level meson.build to check that the
compiler supports C++20 designated initializers. This is not
required, we are just checking and recording the answer. If yes, we
can enable the test module.
Most current compilers likely won't be in C++20 mode by default. This
doesn't change that; we are not doing anything to try to switch the
compiler into that mode. This might be a separate project, but for
now we'll leave that for the user or the test scaffolding.
The VS task on Cirrus CI is changed to provide the required flag to
turn on C++20 mode.
Discussion: https://www.postgresql.org/message-id/flat/CAGECzQR21OnnKiZO_1rLWO0-16kg1JBxnVq-wymYW0-_1cUNtg%40mail.gmail.com
---
.cirrus.tasks.yml | 1 +
meson.build | 14 ++++++++++++++
src/test/modules/test_cplusplusext/meson.build | 7 +------
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 0f32827952f..a22cef063f3 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -782,6 +782,7 @@ task:
CIRRUS_WINDOWS_ERROR_MODE: 0x8001
MESON_FEATURES:
+ -Dcpp_args=/std:c++20
-Dauto_features=disabled
-Dldap=enabled
-Dssl=openssl
diff --git a/meson.build b/meson.build
index c4b4cd4af06..8b134b28a69 100644
--- a/meson.build
+++ b/meson.build
@@ -2176,6 +2176,20 @@ choke me
endif
+# Check whether the C++ compiler supports designated initializers.
+# These are used by PG_MODULE_MAGIC, and we use the result of this
+# test to decide whether to enable the test_cplusplusext test module.
+# Designated initializers only got standardized in C++20. In GCC and
+# Clang they also work when using earlier C++ versions, but MSVC
+# really only supports them when its configured to be in C++20 mode or
+# higher.
+if have_cxx
+ have_cxx_desinit = cxx.compiles('struct S { int x; } s = { .x = 1 };', name: 'C++ designated initializers')
+else
+ have_cxx_desinit = false
+endif
+
+
###############################################################
# Compiler flags
diff --git a/src/test/modules/test_cplusplusext/meson.build b/src/test/modules/test_cplusplusext/meson.build
index d13210ca593..5860464a503 100644
--- a/src/test/modules/test_cplusplusext/meson.build
+++ b/src/test/modules/test_cplusplusext/meson.build
@@ -1,11 +1,6 @@
# Copyright (c) 2025-2026, PostgreSQL Global Development Group
-if not have_cxx
- subdir_done()
-endif
-
-# Currently not supported, to be fixed.
-if cc.get_id() == 'msvc'
+if not have_cxx or not have_cxx_desinit
subdir_done()
endif
--
2.53.0
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-03-31 09:09 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-04-01 05:54 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-03-31 09:09 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On Tue, 31 Mar 2026 at 10:33, Peter Eisentraut <peter@eisentraut.org> wrote:
> Hmm, note that C++ is also used for LLVM/JIT, and by requiring this
> additional feature set we are also imposing new requirements for those
> users. This has not been fully explored, and I hesitate to add such a
> new requirement at the last moment.
I understand the hesitation, but in practice we already impose those
requirements anyway for non-MSVC compilers because test_cplusplusext
doesn't compile without it. So any compiler that would cause problems
with the new featureset would have already complained about that
before.
> But how about this: We add the feature test that you propose and enable
> the extension based on that. See attached patch. This reduces to
> essentially a three-line patch, much simpler than all previous proposals.
If you're still worried, then this sounds like a fine middle-ground
for now. I think we should reconsider adding the automatic /std:c++20
flag for the PG20 dev cycle though.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-04-01 05:54 ` Peter Eisentraut <peter@eisentraut.org>
2026-04-09 11:41 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-04-01 05:54 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On 31.03.26 11:09, Jelte Fennema-Nio wrote:
> On Tue, 31 Mar 2026 at 10:33, Peter Eisentraut <peter@eisentraut.org> wrote:
>> Hmm, note that C++ is also used for LLVM/JIT, and by requiring this
>> additional feature set we are also imposing new requirements for those
>> users. This has not been fully explored, and I hesitate to add such a
>> new requirement at the last moment.
>
> I understand the hesitation, but in practice we already impose those
> requirements anyway for non-MSVC compilers because test_cplusplusext
> doesn't compile without it. So any compiler that would cause problems
> with the new featureset would have already complained about that
> before.
>
>> But how about this: We add the feature test that you propose and enable
>> the extension based on that. See attached patch. This reduces to
>> essentially a three-line patch, much simpler than all previous proposals.
>
> If you're still worried, then this sounds like a fine middle-ground
> for now. I think we should reconsider adding the automatic /std:c++20
> flag for the PG20 dev cycle though.
Ok, I have committed the shown patch.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-04-01 05:54 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-04-09 11:41 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-14 13:10 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 51+ messages in thread
From: Bertrand Drouvot @ 2026-04-09 11:41 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
Hi,
On Wed, Apr 01, 2026 at 07:54:07AM +0200, Peter Eisentraut wrote:
> On 31.03.26 11:09, Jelte Fennema-Nio wrote:
> > On Tue, 31 Mar 2026 at 10:33, Peter Eisentraut <peter@eisentraut.org> wrote:
> > > Hmm, note that C++ is also used for LLVM/JIT, and by requiring this
> > > additional feature set we are also imposing new requirements for those
> > > users. This has not been fully explored, and I hesitate to add such a
> > > new requirement at the last moment.
> >
> > I understand the hesitation, but in practice we already impose those
> > requirements anyway for non-MSVC compilers because test_cplusplusext
> > doesn't compile without it. So any compiler that would cause problems
> > with the new featureset would have already complained about that
> > before.
> >
> > > But how about this: We add the feature test that you propose and enable
> > > the extension based on that. See attached patch. This reduces to
> > > essentially a three-line patch, much simpler than all previous proposals.
> >
> > If you're still worried, then this sounds like a fine middle-ground
> > for now. I think we should reconsider adding the automatic /std:c++20
> > flag for the PG20 dev cycle though.
>
> Ok, I have committed the shown patch.
d50c86e74375 added a comment mentionning that StaticAssertStmt is deprecated, so
we really need the one added in test_cplusplusext.cpp?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-04-01 05:54 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-04-09 11:41 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2026-04-14 13:10 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-16 08:07 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 51+ messages in thread
From: Bertrand Drouvot @ 2026-04-14 13:10 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
Hi,
On Thu, Apr 09, 2026 at 11:41:39AM +0000, Bertrand Drouvot wrote:
> Hi,
>
> On Wed, Apr 01, 2026 at 07:54:07AM +0200, Peter Eisentraut wrote:
> >
> > Ok, I have committed the shown patch.
>
> d50c86e74375 added a comment mentionning that StaticAssertStmt is deprecated, so
> we really need the one added in test_cplusplusext.cpp?
Now that 66ad764c8d5 is in, the only remaining use of StaticAssertStmt() is in
test_cplusplusext.cpp. What about the attached to get rid of it?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachments:
v1-0001-Replace-deprecated-StaticAssertStmt-with-StaticAs.patch (text/x-diff, 1.3K) download
From 5f9cf3b5bfb916f71dcc34a5690ad233a175fc13 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Tue, 14 Apr 2026 12:54:45 +0000
Subject: [PATCH v1] Replace deprecated StaticAssertStmt() with
StaticAssertDecl()
Commit 451650eaacd5 added a test for the StaticAssertStmt() macro in C++
extensions, but it was marked as deprecated in commit d50c86e74375.
There is no need to replace it with StaticAssertDecl() (like 66ad764c8d5 did),
as the exact same StaticAssertDecl() test has also be added in 451650eaacd5.
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/adeQc3I/4dwpeqEb@ip-10-97-1-34.eu-west-3.compute.internal
---
src/test/modules/test_cplusplusext/test_cplusplusext.cpp | 1 -
1 file changed, 1 deletion(-)
100.0% src/test/modules/test_cplusplusext/
diff --git a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
index 93cd7dd07f7..ca66c69fe34 100644
--- a/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
+++ b/src/test/modules/test_cplusplusext/test_cplusplusext.cpp
@@ -51,7 +51,6 @@ test_cplusplus_add(PG_FUNCTION_ARGS)
(void) rtr;
}
- StaticAssertStmt(sizeof(int32) == 4, "int32 should be 4 bytes");
(void) StaticAssertExpr(sizeof(int64) == 8, "int64 should be 8 bytes");
list_free(list);
--
2.34.1
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-04-01 05:54 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-04-09 11:41 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-14 13:10 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2026-04-16 08:07 ` Peter Eisentraut <peter@eisentraut.org>
2026-04-16 11:31 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-04-16 08:07 UTC (permalink / raw)
To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
On 14.04.26 15:10, Bertrand Drouvot wrote:
> Hi,
>
> On Thu, Apr 09, 2026 at 11:41:39AM +0000, Bertrand Drouvot wrote:
>> Hi,
>>
>> On Wed, Apr 01, 2026 at 07:54:07AM +0200, Peter Eisentraut wrote:
>>>
>>> Ok, I have committed the shown patch.
>>
>> d50c86e74375 added a comment mentionning that StaticAssertStmt is deprecated, so
>> we really need the one added in test_cplusplusext.cpp?
>
> Now that 66ad764c8d5 is in, the only remaining use of StaticAssertStmt() is in
> test_cplusplusext.cpp. What about the attached to get rid of it?
This is a test module. Even if the construct is deprecated, we can
still test it.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-02-13 10:28 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-04-01 05:54 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-04-09 11:41 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-14 13:10 ` Re: Make copyObject work in C++ Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-16 08:07 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-04-16 11:31 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
0 siblings, 0 replies; 51+ messages in thread
From: Bertrand Drouvot @ 2026-04-16 11:31 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Jelte Fennema-Nio <postgres@jeltef.nl>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>; Andres Freund <andres@anarazel.de>
Hi,
On Thu, Apr 16, 2026 at 10:07:35AM +0200, Peter Eisentraut wrote:
> On 14.04.26 15:10, Bertrand Drouvot wrote:
> > Hi,
> >
> > On Thu, Apr 09, 2026 at 11:41:39AM +0000, Bertrand Drouvot wrote:
> > > Hi,
> > >
> > > On Wed, Apr 01, 2026 at 07:54:07AM +0200, Peter Eisentraut wrote:
> > > >
> > > > Ok, I have committed the shown patch.
> > >
> > > d50c86e74375 added a comment mentionning that StaticAssertStmt is deprecated, so
> > > we really need the one added in test_cplusplusext.cpp?
> >
> > Now that 66ad764c8d5 is in, the only remaining use of StaticAssertStmt() is in
> > test_cplusplusext.cpp. What about the attached to get rid of it?
>
> This is a test module. Even if the construct is deprecated, we can still
> test it.
Right, but I was thinking that if we introduce a "pg_attribute_deprecated" macro
(like discussed in [1] and [2]) and make use of it for StaticAssertStmt(), then
this test module would generate Warnings.
We can still come back to it should the above be implemented.
[1]: https://postgr.es/m/CA%2BhUKGK2zuRevnNzCpVzLA7ieHnJoYPnDvgtWRcB4pVnOzchhQ%40mail.gmail.com
[2]: https://postgr.es/m/aRGa87Ab0f3ItWRV@ip-10-97-1-34.eu-west-3.compute.internal
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-01-26 10:29 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-26 10:43 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
1 sibling, 1 reply; 51+ messages in thread
From: Peter Eisentraut @ 2026-01-26 10:29 UTC (permalink / raw)
To: Jelte Fennema-Nio <postgres@jeltef.nl>; Andres Freund <andres@anarazel.de>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On 25.01.26 18:52, Jelte Fennema-Nio wrote:
> On Sun Jan 25, 2026 at 5:50 PM CET, Andres Freund wrote:
>> I'm pretty sceptical this is the right direction.
>
> The only other option I can think of is not supporting C++ extension on
> MSVC unless they are compiled with C++20 (or later). I don't
> particularly care about Windows C++ extensions myself, so I personally
> would be fine with that choice. It seems a bit harsh, though.
Maybe it would be enough to only support PG_MODULE_MAGIC (without
arguments) in C++ for now.
That would still require removing the named initializers inside
PG_MODULE_MAGIC_DATA(), but that's only an internal change, and it would
not affect C-language users of PG_MODULE_MAGIC_EXT, and we wouldn't lock
ourselves into a particular style in C++.
Then, maybe in a couple of years, when C++20 is more widely available,
we could enable PG_MODULE_MAGIC_EXT for C++, or design an alternative
construct for C++.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Re: Make copyObject work in C++ Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-26 10:29 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
@ 2026-01-26 10:43 ` Jelte Fennema-Nio <postgres@jeltef.nl>
0 siblings, 0 replies; 51+ messages in thread
From: Jelte Fennema-Nio @ 2026-01-26 10:43 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Andres Freund <andres@anarazel.de>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; Thomas Munro <thomas.munro@gmail.com>
On Mon, 26 Jan 2026 at 11:29, Peter Eisentraut <peter@eisentraut.org> wrote:
> Maybe it would be enough to only support PG_MODULE_MAGIC (without
> arguments) in C++ for now.
You mean by explicitly ifdefing out PG_MODULE_MAGIC_EXT to make it
unusable in C++? Or just not adding the additional documentation that
I added in my patch?
I'm currently using PG_MODULE_MAGIC_EXT in the C++ extension that I
maintain, and I'd prefer to continue doing so. Especially because it
(currently) doesn't have to work on MSVC for my purposes.
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
@ 2026-02-04 15:54 ` Bryan Green <dbryan.green@gmail.com>
2026-02-07 09:33 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
1 sibling, 1 reply; 51+ messages in thread
From: Bryan Green @ 2026-02-04 15:54 UTC (permalink / raw)
To: pgsql-hackers@lists.postgresql.org
On 1/25/2026 6:42 AM, Jelte Fennema-Nio wrote:
> On Tue Jan 20, 2026 at 5:28 PM CET, Peter Eisentraut wrote:
>> I have split your first patch further. For a start, I left out the
>> PG_MODULE_MAGIC*-related changes and disabled the module under MSVC.
>> This has been committed. I plan to let the buildfarm run with it for
>> a day or two and then add in the basic MSVC support.
>
> To hopefully make your life a bit easier. Here's a rebased version that
> enables the MSVC support again, with an updated commit message.
>
This causes the build to break on VS 2022. Versions prior do not have
support for __typeof_unqual__. This would have led to
HAVE_TYPEOF_UNQUAL being not defined on the buildfarm causing the
fallback to copyObjectImpl() for VS 2019.
When you build on VS 2022 you will get an error:
../src/backend/commands/event_trigger.c(1901): error C2100: you cannot
dereference an operand of type 'void'
VS 2022 (MSVC) does not handle the void * dereference the way gcc/clang
does (thanks to GNU extensions, I believe). It exposes
__typeof_unqual__ even it C11, but enforces strict C semantics on the
void * dereference. To work on this platform the call
copyObject(lfirst(cell)) would need to have a cast to the correct
concrete type: copyObject((Node *)lfirst(cell)).
I was about to update to VS 2026, but now I think I should have an
instance of VS from 2019, 2022, and 2026.
--
Bryan Green
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 51+ messages in thread
* Re: Make copyObject work in C++
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Re: Make copyObject work in C++ Peter Eisentraut <peter@eisentraut.org>
2026-01-25 12:42 ` Re: Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-04 15:54 ` Re: Make copyObject work in C++ Bryan Green <dbryan.green@gmail.com>
@ 2026-02-07 09:33 ` Peter Eisentraut <peter@eisentraut.org>
0 siblings, 0 replies; 51+ messages in thread
From: Peter Eisentraut @ 2026-02-07 09:33 UTC (permalink / raw)
To: Bryan Green <dbryan.green@gmail.com>; pgsql-hackers@lists.postgresql.org
On 04.02.26 16:54, Bryan Green wrote:
> On 1/25/2026 6:42 AM, Jelte Fennema-Nio wrote:
>> On Tue Jan 20, 2026 at 5:28 PM CET, Peter Eisentraut wrote:
>>> I have split your first patch further. For a start, I left out the
>>> PG_MODULE_MAGIC*-related changes and disabled the module under MSVC.
>>> This has been committed. I plan to let the buildfarm run with it for
>>> a day or two and then add in the basic MSVC support.
>>
>> To hopefully make your life a bit easier. Here's a rebased version that
>> enables the MSVC support again, with an updated commit message.
>>
> This causes the build to break on VS 2022. Versions prior do not have
> support for __typeof_unqual__. This would have led to
> HAVE_TYPEOF_UNQUAL being not defined on the buildfarm causing the
> fallback to copyObjectImpl() for VS 2019.
>
> When you build on VS 2022 you will get an error:
> ../src/backend/commands/event_trigger.c(1901): error C2100: you cannot
> dereference an operand of type 'void'
>
> VS 2022 (MSVC) does not handle the void * dereference the way gcc/clang
> does (thanks to GNU extensions, I believe). It exposes
> __typeof_unqual__ even it C11, but enforces strict C semantics on the
> void * dereference. To work on this platform the call
> copyObject(lfirst(cell)) would need to have a cast to the correct
> concrete type: copyObject((Node *)lfirst(cell)).
>
> I was about to update to VS 2026, but now I think I should have an
> instance of VS from 2019, 2022, and 2026.
I have reverted this patch for now to research it further.
^ permalink raw reply [nested|flat] 51+ messages in thread
end of thread, other threads:[~2026-04-16 11:31 UTC | newest]
Thread overview: 51+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-05 14:46 Make copyObject work in C++ Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-07 19:45 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 08:00 ` Peter Eisentraut <peter@eisentraut.org>
2025-12-08 14:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-12-08 15:31 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-08 08:11 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-14 16:56 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-08 07:57 ` Peter Eisentraut <peter@eisentraut.org>
2025-12-08 08:33 ` David Geier <geidav.pg@gmail.com>
2025-12-08 08:52 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-09 12:58 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2025-12-16 12:28 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-03 09:32 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-10 11:09 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-14 15:59 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-17 15:25 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-20 16:28 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-20 16:38 ` Andres Freund <andres@anarazel.de>
2026-01-20 19:07 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-20 19:15 ` Andres Freund <andres@anarazel.de>
2026-01-25 12:42 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 16:50 ` Andres Freund <andres@anarazel.de>
2026-01-25 17:52 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-25 20:06 ` Andres Freund <andres@anarazel.de>
2026-01-26 10:47 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-13 10:28 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-17 09:24 ` Peter Eisentraut <peter@eisentraut.org>
2026-02-19 08:31 ` Peter Eisentraut <peter@eisentraut.org>
2026-02-20 09:47 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:40 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-27 16:52 ` Peter Eisentraut <peter@eisentraut.org>
2026-02-28 11:31 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-02 10:56 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-06 09:23 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-09 08:39 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-13 09:08 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-23 09:27 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-23 09:58 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-27 11:23 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-29 22:53 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-03-31 08:33 ` Peter Eisentraut <peter@eisentraut.org>
2026-03-31 09:09 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-04-01 05:54 ` Peter Eisentraut <peter@eisentraut.org>
2026-04-09 11:41 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-14 13:10 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-04-16 08:07 ` Peter Eisentraut <peter@eisentraut.org>
2026-04-16 11:31 ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-01-26 10:29 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-26 10:43 ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-02-04 15:54 ` Bryan Green <dbryan.green@gmail.com>
2026-02-07 09:33 ` Peter Eisentraut <peter@eisentraut.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox