From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B88493848410; Fri, 4 Jun 2021 13:11:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B88493848410 From: "terra at gnome dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/100903] New: Bogus "zero as null pointer constant" warning Date: Fri, 04 Jun 2021 13:11:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: terra at gnome dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jun 2021 13:11:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100903 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=3D50926&action=3Dedit 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 point= er 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.=20 Doing this right is likely to require compiler support. # cat uuu.C #include int foo(std::partial_ordering po) { return po < 0; } # g++ -Wall -std=3Dgnu++20 -Wzero-as-null-pointer-constant -c uuu.C uuu.C: In function =E2=80=98int foo(std::partial_ordering)=E2=80=99: 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=3D/usr/local/products/gcc/11.1.0/bin/g++ COLLECT_LTO_WRAPPER=3D/usr/local/products/gcc/11.1.0/lib/gcc/x86_64-suse-li= nux/11.1.0/lto-wrapper Target: x86_64-suse-linux Configured with: ../../gcc-11.1.0/configure --enable-languages=3Dc,c++,fort= ran --enable-targets=3Dx86_64-suse-linux,i686-suse-linux --prefix=3D/usr/local/products/gcc/11.1.0 --with-gnu-as --with-as=3D/usr/local/products/gcc/binutils-2.36.1/bin/as --with-gnu-ld --with-ld=3D/usr/local/products/gcc/binutils-2.36.1/bin/ld --enable-link-mu= tex --enable-gnu-indirect-functions --enable-linux-futex --enable-threads=3Dpos= ix --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=3Dnew x86_64-suse-linux Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.1.0 (GCC)=