postgresql/src/include
Peter Eisentraut 59292f7aac 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 *.

This is the second attempt, after the first attempt in commit
4cfce4e62c was reverted.  The following two points address problems
with the earlier version:

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.

Unlike the typeof test, the typeof_unqual test also tests with a void
pointer similar to how copyObject() would use it, because that is not
handled by MSVC, so we want the test to fail there.

Reviewed-by: David Geier <geidav.pg@gmail.com>
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://www.postgresql.org/message-id/flat/92f9750f-c7f6-42d8-9a4a-85a3cbe808f3%40eisentraut.org
2026-03-13 07:06:57 +01:00
..
access nbtree: Avoid allocating _bt_search stack. 2026-03-12 13:22:36 -04:00
archive Update copyright for 2026 2026-01-01 13:24:10 -05:00
backup Update copyright for 2026 2026-01-01 13:24:10 -05:00
bootstrap Simplify creation of built-in functions with non-default ACLs. 2026-03-05 17:43:09 -05:00
catalog Introduce the REPACK command 2026-03-10 19:56:39 +01:00
commands Introduce the REPACK command 2026-03-10 19:56:39 +01:00
common Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
datatype Update copyright for 2026 2026-01-01 13:24:10 -05:00
executor Enable fast default for domains with non-volatile constraints 2026-03-12 18:05:01 -04:00
fe_utils pg_dumpall: Fix handling of conflicting options. 2026-03-06 14:00:04 -06:00
foreign CREATE SUBSCRIPTION ... SERVER. 2026-03-06 08:27:56 -08:00
jit Fix typos and inconsistencies in code and comments 2026-01-05 09:19:15 +09:00
lib Make use of pg_popcount() in more places. 2026-02-23 09:26:00 -06:00
libpq Don't include proc.h in shm_mq.h 2026-02-27 10:53:47 +01:00
mb Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
nodes Change copyObject() to use typeof_unqual 2026-03-13 07:06:57 +01:00
optimizer Convert NOT IN sublinks to anti-joins when safe 2026-03-12 09:45:18 +09:00
parser Introduce the REPACK command 2026-03-10 19:56:39 +01:00
partitioning Update copyright for 2026 2026-01-01 13:24:10 -05:00
pch Update copyright for 2026 2026-01-01 13:24:10 -05:00
port Fix some -Wcast-qual warnings 2026-02-27 21:57:33 +01:00
portability instrumentation: Drop INSTR_TIME_SET_CURRENT_LAZY macro 2026-02-26 10:39:29 -05:00
postmaster Fix some -Wcast-qual warnings 2026-02-27 21:57:33 +01:00
regex Update copyright for 2026 2026-01-01 13:24:10 -05:00
replication Avoid including utils/timestamp.h in conflict.h. 2026-02-23 10:19:05 +05:30
rewrite Update copyright for 2026 2026-01-01 13:24:10 -05:00
snowball Update to latest Snowball sources. 2026-01-05 15:22:37 -05:00
statistics Add support for "mcv" in pg_restore_extended_stats() 2026-01-29 12:14:08 +09:00
storage bufmgr: Remove the, now obsolete, BM_JUST_DIRTIED 2026-03-11 14:58:29 -04:00
tcop Introduce the REPACK command 2026-03-10 19:56:39 +01:00
tsearch Replace pg_mblen() with bounds-checked versions. 2026-02-09 12:44:04 +13:00
utils Extend DomainHasConstraints() to optionally check constraint volatility 2026-03-12 18:04:16 -04:00
.gitignore Use <stdint.h> and <inttypes.h> for c.h integers. 2024-12-04 15:05:38 +13:00
c.h Change copyObject() to use typeof_unqual 2026-03-13 07:06:57 +01:00
fmgr.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
funcapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
getopt_long.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
Makefile Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:39 +09:00
meson.build Ensure that all three build methods install the same set of files. 2026-02-16 15:20:15 -05:00
miscadmin.h Add password expiration warnings. 2026-02-11 10:36:15 -06:00
pg_config.h.in Change copyObject() to use typeof_unqual 2026-03-13 07:06:57 +01:00
pg_config_manual.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_getopt.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_trace.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgstat.h Don't include wait_event.h in pgstat.h 2026-03-06 16:24:58 +01:00
pgtar.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgtime.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
port.h strnlen() is now required 2026-01-08 08:51:20 +01:00
postgres.h Remove Int8GetDatum function 2026-03-11 10:46:08 +01:00
postgres_ext.h Move pg_int64 back to postgres_ext.h 2025-09-16 10:48:56 +02:00
postgres_fe.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
varatt.h Improve type handling of varlena structures 2026-02-11 07:33:24 +09:00
windowapi.h Update copyright for 2026 2026-01-01 13:24:10 -05:00