Re: Make copyObject work in C++
David Geier <geidav.pg@gmail.com>
From: David Geier <geidav.pg@gmail.com>
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>
Date: 2025-12-08T08:33:10Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Enable test_cplusplusext with MSVC
- c05ad248f99c 19 (unreleased) landed
-
Disable some C++ warnings in MSVC
- 82a7cbea747c 19 (unreleased) landed
-
meson: Make room for C++-only warning flags for MSVC
- 4c83f1253593 19 (unreleased) landed
-
Make fixed-length list building macros work in C++
- f8e7ca328510 19 (unreleased) landed
-
Make unconstify and unvolatize use StaticAssertVariableIsOfTypeMacro
- 258248d0bdbf 19 (unreleased) landed
-
Use typeof everywhere instead of compiler specific spellings
- e2308350c9b7 19 (unreleased) landed
-
Test List macros in C++ extensions
- 3d28ecb5ac76 19 (unreleased) landed
-
Test most StaticAssert macros in C++ extensions
- 451650eaacd5 19 (unreleased) landed
-
Fix for C++ compatibility
- b4555cb070f1 19 (unreleased) landed
-
tests: Add a test C++ extension module
- 476b35d4e311 19 (unreleased) landed
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