agora inbox for pgsql-committers@postgresql.orghelp / color / mirror / Atom feed
pgsql: Replace __builtin_types_compatible_p with _Generic 2+ messages / 1 participants [nested] [flat]
* pgsql: Replace __builtin_types_compatible_p with _Generic @ 2026-07-14 08:40 Peter Eisentraut <peter@eisentraut.org> 0 siblings, 1 reply; 2+ messages in thread From: Peter Eisentraut @ 2026-07-14 08:40 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Replace __builtin_types_compatible_p with _Generic _Generic is the C11 standard equivalent (and superset) of __builtin_types_compatible_p, so by replacing the latter with the former, we can now rely on this working on all compilers, instead of previously just with GCC-compatible ones. And we can drop a configure test. This affects StaticAssertVariableIsOfType() and StaticAssertVariableIsOfTypeMacro() and indirectly unconstify() and unvolatize(). Neither _Generic nor __builtin_types_compatible_p works in C++, so this does not change that, but this adds an explicit code comment about that. There are some subtle behavior changes, but these do not affect cases that are in use or likely to be useful. _Generic does lvalue conversion on the controlling expression, which means it drops top-level qualifiers and converts arrays to pointers. __builtin_types_compatible_p on the other hand, supports arrays and just ignores qualifiers. So before, StaticAssertVariableIsOfType(x, const int) might have worked, but now it does not. (But note that it would previously have succeeded even if x was a non-const int, so this usage would always have been dubious.) Also, StaticAssertVariableIsOfType(y, char[]) would have worked, but now you need to write char *. (But this is not backward compatible, because char * would previously not have succeeded.) Similarly, unconstify of non-pointers, like unconstify(const int, x) would previously have worked, but this was just by accident and never useful (you can just assign directly, without a cast), and the C++ implementation rejects non-pointers anyway. Some comments are added to explain this a bit. There are no current uses affected by this. Note that even though we have required C11 since f5e0186f865, we have not made use of _Generic until now (except in an MSVC-specific case in commit 59c2f03d1ec). This now raises the effective compiler requirement on the trailing edge slightly from GCC 4.8 to GCC 4.9. This in turn means that we effectively drop support for RHEL 7. Author: Peter Eisentraut <peter@eisentraut.org> Co-authored-by: Thomas Munro <thomas.munro@gmail.com> Co-authored-by: Jelte Fennema-Nio <postgres@jeltef.nl> Discussion: https://www.postgresql.org/message-id/flat/CA+hUKGL7trhWiJ4qxpksBztMMTWDyPnP1QN+Lq341V7QL775DA@mail.... Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/d15a6bc2e16d4b330d6d455e41ce1ab3395d8e03 Modified Files -------------- config/c-compiler.m4 | 19 ------------------- configure | 30 ------------------------------ configure.ac | 1 - meson.build | 15 --------------- src/include/c.h | 32 ++++++++++++++++---------------- src/include/pg_config.h.in | 3 --- 6 files changed, 16 insertions(+), 84 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: pgsql: Replace __builtin_types_compatible_p with _Generic @ 2026-07-14 13:00 Peter Eisentraut <peter@eisentraut.org> parent: Peter Eisentraut <peter@eisentraut.org> 0 siblings, 0 replies; 2+ messages in thread From: Peter Eisentraut @ 2026-07-14 13:00 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org On 14.07.26 10:40, Peter Eisentraut wrote: > Replace __builtin_types_compatible_p with _Generic > Note that even though we have required C11 since f5e0186f865, we have > not made use of _Generic until now (except in an MSVC-specific case in > commit 59c2f03d1ec). This now raises the effective compiler > requirement on the trailing edge slightly from GCC 4.8 to GCC 4.9. > This in turn means that we effectively drop support for RHEL 7. FYI, it is expected that some trailing-edge buildfarm members will fail to build now. I'm in contact with the owners to decommission those. ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-07-14 13:00 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-07-14 08:40 pgsql: Replace __builtin_types_compatible_p with _Generic Peter Eisentraut <peter@eisentraut.org> 2026-07-14 13:00 ` Peter Eisentraut <peter@eisentraut.org>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox