https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903
Bug ID: 100903 Summary: Bogus "zero as null pointer constant" warning Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: terra at gnome dot org Target Milestone: --- Created attachment 50926 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50926&action=edit Preprocesses source code g++ emits a bogus warning when a std::partial_ordering value is compared to a literal 0. See also bug 95242. The standard is crazy-strict here. Anything other than a literal 0 is undefined behaviour. Allowed: 0, 0LL, 0'0'0'0, 0x0. No good: +0, nullptr, (void*)0, 0+0, '\0', (0,nullptr). gcc incorrectly allows nullptr and (0,nullptr), but rejects the others. The library tries to do that with a construct that mainly allows null pointer constants. That leads to the warning when you actually supply the 0 you are supposed to. Suggestion: just use an int argument. That's wrong in different ways (and might cause warnings with 0LL which is allowed), but it matches 0 better. Doing this right is likely to require compiler support. # cat uuu.C #include <compare> int foo(std::partial_ordering po) { return po < 0; } # g++ -Wall -std=gnu++20 -Wzero-as-null-pointer-constant -c uuu.C uuu.C: In function ‘int foo(std::partial_ordering)’: uuu.C:6:15: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant] 6 | return po < 0; | ^ # g++ -v Using built-in specs. COLLECT_GCC=/usr/local/products/gcc/11.1.0/bin/g++ COLLECT_LTO_WRAPPER=/usr/local/products/gcc/11.1.0/lib/gcc/x86_64-suse-linux/11.1.0/lto-wrapper Target: x86_64-suse-linux Configured with: ../../gcc-11.1.0/configure --enable-languages=c,c++,fortran --enable-targets=x86_64-suse-linux,i686-suse-linux --prefix=/usr/local/products/gcc/11.1.0 --with-gnu-as --with-as=/usr/local/products/gcc/binutils-2.36.1/bin/as --with-gnu-ld --with-ld=/usr/local/products/gcc/binutils-2.36.1/bin/ld --enable-link-mutex --enable-gnu-indirect-functions --enable-linux-futex --enable-threads=posix --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new x86_64-suse-linux Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.1.0 (GCC)