pgsql: Make typeof and typeof_unqual fallback definitions work on C++11

Started by Peter Eisentraut3 months ago5 messagescomitters
Jump to latest
#1Peter Eisentraut
peter_e@gmx.net

Make typeof and typeof_unqual fallback definitions work on C++11

These macros were unintentionally using C++14 features. This replaces
them with valid C++11 code.

Tested locally by compiling with -std=c++11 (which reproduced the
original issue).

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: /messages/by-id/92f9750f-c7f6-42d8-9a4a-85a3cbe808f3@eisentraut.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cd083b54bd675a6c941b2d52f398cebbf95b060f

Modified Files
--------------
src/include/c.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

#2Melanie Plageman
melanieplageman@gmail.com
In reply to: Peter Eisentraut (#1)
Re: pgsql: Make typeof and typeof_unqual fallback definitions work on C++11

On Sun, Mar 15, 2026 at 2:48 AM Peter Eisentraut <peter@eisentraut.org> wrote:

Make typeof and typeof_unqual fallback definitions work on C++11

These macros were unintentionally using C++14 features. This replaces
them with valid C++11 code.

Seems like this broke at least canebrake [1]https://buildfarm.postgresql.org/cgi-bin/show_log.pl?dt=2026-03-13+20%3A54%3A31&amp;nm=canebrake

/home/bf/bf-build/canebrake/HEAD/pgsql.build/../pgsql/src/backend/bootstrap/bootstrap.c:1150:3:
error: call to undeclared function '__typeof_unqual__'; ISO C99 and
later do not support implicit function declarations
[-Wimplicit-function-declaration]
/home/bf/bf-build/canebrake/HEAD/pgsql.build/../pgsql/src/backend/bootstrap/bootstrap.c:1150:3:
error: expected expression

- Melanie

[1]: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?dt=2026-03-13+20%3A54%3A31&amp;nm=canebrake

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Melanie Plageman (#2)
Re: pgsql: Make typeof and typeof_unqual fallback definitions work on C++11

Melanie Plageman <melanieplageman@gmail.com> writes:

On Sun, Mar 15, 2026 at 2:48 AM Peter Eisentraut <peter@eisentraut.org> wrote:

Make typeof and typeof_unqual fallback definitions work on C++11

Seems like this broke at least canebrake [1]

Doesn't appear to have satisfied any of the previously-broken animals
either. It looks like the C compiler is okay but building bitcode
with clang is not okay. We're really going to need separate
definitions for the two cases.

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#3)
Re: pgsql: Make typeof and typeof_unqual fallback definitions work on C++11

I wrote:

Doesn't appear to have satisfied any of the previously-broken animals
either. It looks like the C compiler is okay but building bitcode
with clang is not okay. We're really going to need separate
definitions for the two cases.

After noting that ladybug is one of the failing animals, I was
able to reproduce the failure locally on a Fedora 40 installation.
This system has

$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ --version
g++ (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ clang --version
clang version 18.1.8 (Fedora 18.1.8-2.fc40)

So far as I can tell, this version of clang does not recognize
__typeof_unqual__ at all. It will take typeof_unqual, but only
with -std=c23 which we are not passing it. So the short answer
is that this is not good enough:

We test the underscore variant first so that there is a higher chance
that clang used for bitcode also supports it, since we don't test that
separately.

We could get away with not checking clang separately as long as
we weren't using any bleeding-edge C features, but this patch
is trying to do exactly that. I think we are going to have to
explicitly check all three of CC, CXX, CLANG and cope with the
case that they're all different on this point.

regards, tom lane

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Melanie Plageman (#2)
Re: pgsql: Make typeof and typeof_unqual fallback definitions work on C++11

On 15.03.26 16:28, Melanie Plageman wrote:

On Sun, Mar 15, 2026 at 2:48 AM Peter Eisentraut <peter@eisentraut.org> wrote:

Make typeof and typeof_unqual fallback definitions work on C++11

These macros were unintentionally using C++14 features. This replaces
them with valid C++11 code.

Seems like this broke at least canebrake [1]

/home/bf/bf-build/canebrake/HEAD/pgsql.build/../pgsql/src/backend/bootstrap/bootstrap.c:1150:3:
error: call to undeclared function '__typeof_unqual__'; ISO C99 and
later do not support implicit function declarations
[-Wimplicit-function-declaration]
/home/bf/bf-build/canebrake/HEAD/pgsql.build/../pgsql/src/backend/bootstrap/bootstrap.c:1150:3:
error: expected expression

Please see discussion here:
/messages/by-id/ff129805-1516-478a-a438-145880165c58@eisentraut.org