Sam James <s...@gentoo.org> writes:

> From: Joseph Myers <josmy...@redhat.com>
>
> As reported in bug 112556, GCC wrongly rejects conversion of null
> pointer constants with bool or enum type to pointers in
> convert_for_assignment (assignment, initialization, argument passing,
> return).  Fix the code there to allow BOOLEAN_TYPE and ENUMERAL_TYPE;
> it already allowed INTEGER_TYPE and BITINT_TYPE.
>
> This bug (together with -std=gnu23 meaning false has type bool rather
> than int) has in turn resulted in people thinking they need to fix
> code using false as a null pointer constant for C23 compatibility.
> While such a usage is certainly questionable, it has nothing to do
> with C23 compatibility and the right place for warnings about such
> usage is -Wzero-as-null-pointer-constant.  I think it would be
> appropriate to extend -Wzero-as-null-pointer-constant to cover
> BOOLEAN_TYPE, ENUMERAL_TYPE and BITINT_TYPE (in all the various
> contexts in which that option generates warnings), though this patch
> doesn't do anything about that option.
>
> Bootstrapped with no regressions for x86-64-pc-linux-gnu.
>
>       PR c/112556
>
> gcc/c/
>       * c-typeck.cc (convert_for_assignment): Allow conversion of
>       ENUMERAL_TYPE and BOOLEAN_TYPE null pointer constants to pointers.
>
> gcc/testsuite/
>       * gcc.dg/c11-null-pointer-constant-1.c,
>       gcc.dg/c23-null-pointer-constant-1.c: New tests.
>
> (cherry picked from commit 3d525fce70fa0ffa0b22af6e213643e1ceca5ab5)
> ---
> As discussed on the PR, I feel like this is worth having for 14 as we're
> asking upstreams to try reproduce issues w/ -std=gnu23 (or -std=c23) if
> they don't have access to GCC 15, and this bug may lead to them being
> confused.
>
> Regtested on x86_64-pc-linux-gnu with no regressions.
>
> OK?

Ping, as 14 RC is tomorrow.

Reply via email to