aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2024-11-18 22:24:48 +0000
committerJoseph Myers <josmyers@redhat.com>2024-11-18 22:26:21 +0000
commit3d525fce70fa0ffa0b22af6e213643e1ceca5ab5 (patch)
tree15296e6c9acc973d89211c207e3fdcf384ff672b /libcpp
parentea1506adbe7544bb51fc74a0fae3fa6fa0c68661 (diff)
downloadgcc-3d525fce70fa0ffa0b22af6e213643e1ceca5ab5.zip
gcc-3d525fce70fa0ffa0b22af6e213643e1ceca5ab5.tar.gz
gcc-3d525fce70fa0ffa0b22af6e213643e1ceca5ab5.tar.bz2
c: Allow bool and enum null pointer constants [PR112556]
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.
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions