Bug 96278 - three-way comparison operator comparison to 0: spurious nullptr warning
Summary: three-way comparison operator comparison to 0: spurious nullptr warning
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on: 95242
Blocks:
  Show dependency tree / graph
 
Reported: 2020-07-22 05:05 UTC by DV Henkel-Wallace
Modified: 2021-08-12 05:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 10.2.0, 11.0
Last reconfirmed: 2021-08-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description DV Henkel-Wallace 2020-07-22 05:05:21 UTC
Bug in g++ 10.1.0 with libstdc++

compile following program doing `g++-10 -std=c++20 -Wzero-as-null-pointer-constant`

#include <iostream>
#include <compare>

int main () {
  bool result { (1 <=> 2) < 0 };
  std::cout << (result ? "Yes" : "No") << std::endl;
}

produces the error:

   foo.cc:5:27: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]

Also compiler-synthesized comparisons will generate this which is especially confusing as they can happen when calling a library function that needs the '<' operator.

the exact version of GCC: 10.1.0

the system type: MacOS 10.15 (and Ubuntu 18.4 LTS using apt-get of gcc 10)

the options given when GCC was configured/built: (homebrew version): Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/10.1.0 --libdir=/usr/local/Cellar/gcc/10.1.0/lib/gcc/10 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 10.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SED=/usr/bin/sed
Comment 1 Drea Pinski 2020-07-22 05:45:17 UTC
I think this is a dup of bug 95242.
Comment 2 DV Henkel-Wallace 2020-07-22 06:27:06 UTC
(In reply to Andrew Pinski from comment #1)
> I think this is a dup of bug 95242.

Could be: I'm not sure if Jason's change applies only to synthesized comparators or not (that was the case described in 95242 and was the second case I mentioned).  I hope it is already fixed.

However the test case I submitted is the user-supplied 0 literal per the standard the standard, not a synthetic case.  So might or might not be; I no longer grok the gcc internals so can't tell myself.  Thanks -d
Comment 3 Martin Sebor 2020-07-23 15:28:43 UTC
Confirmed with today's top of trunk and GCC 10.2.