]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Update checks on constexpr floating-point initializers
authorJoseph Myers <joseph@codesourcery.com>
Thu, 2 Feb 2023 20:07:08 +0000 (20:07 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Thu, 2 Feb 2023 20:07:08 +0000 (20:07 +0000)
commit66337ff8a44559fa4600014786051a2bdd1f986b
tree62e2cf7940c5b27d54abdf792979a2bdd2b5d1d3
parent5c43f06c228d169c370e99fa009154344fa305b8
c: Update checks on constexpr floating-point initializers

WG14 has agreed some changes (detailed at the end of N3082) to the
rules on constexpr initializers for floating types.  Update GCC's
implementation to match: binary initializers are now allowed for
decimal types, and real initializers for complex types, but signaling
NaN initializers can't be used for a different type with the same
mode.

There are also changes to the constexpr rules for pointer types
(allowing null pointer address constants that aren't null pointer
constants), which I'll deal with separately.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
* c-typeck.cc: Include "realmpfr.h".
(constexpr_init_fits_real_type): Do not allow signaling NaN
conversions to different types with the same mode.  Handle
conversions from binary to decimal types.
(check_constexpr_init): Do not disallow real initializers for
complex types.  Do not disallow binary initializers for decimal
floating types.

gcc/testsuite/
* gcc.dg/c2x-constexpr-1.c: Test constexpr initializers of complex
types with real initializers are allowed.
* gcc.dg/c2x-constexpr-3.c: Do not test for constexpr initializers
of complex types with real initializers being disallowed.
* gcc.dg/c2x-constexpr-8.c: Add tests of signaling NaN complex
initializers.
* gcc.dg/c2x-constexpr-9.c: Add more tests.
* gcc.dg/dfp/c2x-constexpr-dfp-1.c: Add tests of binary floating
initializers for decimal types.
* gcc.dg/dfp/c2x-constexpr-dfp-2.c: Change tests of binary
initializers for decimal types.  Add more tests of decimal
initializers for binary types.
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/c2x-constexpr-1.c
gcc/testsuite/gcc.dg/c2x-constexpr-3.c
gcc/testsuite/gcc.dg/c2x-constexpr-8.c
gcc/testsuite/gcc.dg/c2x-constexpr-9.c
gcc/testsuite/gcc.dg/dfp/c2x-constexpr-dfp-1.c
gcc/testsuite/gcc.dg/dfp/c2x-constexpr-dfp-2.c