c: Update nullptr_t comparison checks
authorJoseph Myers <joseph@codesourcery.com>
Thu, 2 Feb 2023 23:29:45 +0000 (23:29 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Thu, 2 Feb 2023 23:29:45 +0000 (23:29 +0000)
commit0b8693fc87b1453bdacfa5910091be15da671d2a
treeddaefde49fa3590b4916c0ac602a661bbb5cb637
parent07c87fce63541846ca2951e22dac04fcaa66475f
c: Update nullptr_t comparison checks

WG14 has agreed to allow equality comparisons between pointers and
nullptr_t values that are not null pointer constants (this was
previously an exceptional case where such nullptr_t values were
handled differently from null pointer constants; other places in the
standard allowed nullptr_t values, whether or not those values are
null pointer constants, in the same contexts as null pointer
constants); see the wording at the end of N3077.  Update GCC's
implementation to match this change.

There are also changes to allow null pointer constants of integer or
pointer type to be converted to nullptr_t (by assignment, cast or
conversion as if by assignment), which I'll deal with separately.

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

gcc/c/
* c-typeck.cc (build_binary_op): Allow comparisons between
pointers and nullptr_t values that are not null pointer constants.

gcc/testsuite/
* gcc.dg/c2x-constexpr-3.c: Do not expect comparison of nullptr_t
and pointer to be disallowed.
* gcc.dg/c2x-nullptr-1.c: Test comparisons of nullptr_t and
pointers are allowed.
* gcc.dg/c2x-nullptr-3.c: Do not test that comparisons of
nullptr_t and pointers are disallowed.
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/c2x-constexpr-3.c
gcc/testsuite/gcc.dg/c2x-nullptr-1.c
gcc/testsuite/gcc.dg/c2x-nullptr-3.c