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 <[email protected]> Co-authored-by: Thomas Munro <[email protected]> Co-authored-by: Jelte Fennema-Nio <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/ca+hukgl7trhwij4qxpksbztmmtwdypnp1qn+lq341v7ql77...@mail.gmail.com 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(-)
