Re: Make copyObject work in C++

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: Make copyObject work in C++
Date: 2025-12-08 07:57:17
Message-ID: 1bec56e5-aef9-4d3b-b4ee-723c6575a44e@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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?

Attachment Content-Type Size
0001-Change-copyObject-to-use-typeof_unqual.patch text/plain 5.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-12-08 08:00:55 Re: Make copyObject work in C++
Previous Message Bertrand Drouvot 2025-12-08 07:43:34 Re: More const-marking cleanup