]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Change copyObject() to use typeof_unqual
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 4 Feb 2026 07:39:55 +0000 (08:39 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 4 Feb 2026 08:22:41 +0000 (09:22 +0100)
commit4cfce4e62c8f09f5b1f6a7f69760ca46a74406e2
tree201aade78f0a86d20fc433b8f660f6116ba8584e
parentc8ec74713bf2c703c19f231ea4d1e6479630c72d
Change copyObject() to use typeof_unqual

Currently, when the argument of copyObject() is const-qualified, the
return type is also, because the use of typeof carries over all the
qualifiers.  This is incorrect, since the point of copyObject() is to
make a copy to mutate.  But apparently no code ran into it.

The new implementation uses typeof_unqual, which drops the qualifiers,
making this work correctly.

typeof_unqual is standardized in C23, but all recent versions of all
the usual compilers support it even in non-C23 mode, at least as
__typeof_unqual__.  We add a configure/meson test for typeof_unqual
and __typeof_unqual__ and use it if it's available, else we use the
existing fallback of just returning void *.

Reviewed-by: David Geier <geidav.pg@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/92f9750f-c7f6-42d8-9a4a-85a3cbe808f3%40eisentraut.org
config/c-compiler.m4
configure
configure.ac
meson.build
src/include/nodes/nodes.h
src/include/pg_config.h.in