public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100903] New: Bogus "zero as null pointer constant" warning
@ 2021-06-04 13:11 terra at gnome dot org
  2021-06-04 14:53 ` [Bug libstdc++/100903] " jakub at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: terra at gnome dot org @ 2021-06-04 13:11 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-01-25 17:19 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04 13:11 [Bug libstdc++/100903] New: Bogus "zero as null pointer constant" warning terra at gnome dot org
2021-06-04 14:53 ` [Bug libstdc++/100903] " jakub at gcc dot gnu.org
2021-06-04 16:14 ` terra at gnome dot org
2021-06-04 17:16 ` redi at gcc dot gnu.org
2021-06-04 17:17 ` redi at gcc dot gnu.org
2021-06-04 17:21 ` redi at gcc dot gnu.org
2021-06-04 17:21 ` redi at gcc dot gnu.org
2021-06-07 15:01 ` jakub at gcc dot gnu.org
2023-11-16 10:24 ` marc.mutz at hotmail dot com
2023-11-16 14:22 ` redi at gcc dot gnu.org
2023-11-16 14:35 ` redi at gcc dot gnu.org
2023-11-16 15:07 ` redi at gcc dot gnu.org
2023-11-16 16:35 ` terra at gnome dot org
2023-11-16 17:15 ` redi at gcc dot gnu.org
2023-11-21  0:30 ` headch at gmail dot com
2024-01-25 17:19 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).