https://bugs.llvm.org/show_bug.cgi?id=49008
Bug ID: 49008
Summary: false positive -Wzero-as-null-pointer-constant
involving spaceship operator
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++2a
Assignee: unassignedclangb...@nondot.org
Reporter: mizve...@gmail.com
CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk
Clang produces very confusing diagnostics with -Wzero-as-null-pointer-constant,
involving spaceship comparisons.
The example below is a creduction with further manual intervention from a
program compiled for mingw32, where this warning would get triggered for
seemingly innocent comparisons.
clang++ -Wzero-as-null-pointer-constant -std=c++20 -fsyntax-only test.cc
```
namespace std {
struct strong_ordering {
int n;
constexpr strong_ordering(int n) : n(n) {}
static const strong_ordering less, equal, greater;
friend constexpr bool operator<(strong_ordering a, void*) { return a.n; }
};
constexpr strong_ordering strong_ordering::less{-1}, strong_ordering::equal{0},
strong_ordering::greater{1};
} // namespace std
struct bb { int bf; };
constexpr auto operator<=>(bb bl, bb bm) { return bl.bf <=> bm.bf; }
static_assert(bb{0} < bb{1});
```
Compiler output:
```
test.cc:13:21: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
static_assert(bb{0} < bb{1});
^
nullptr
test.cc:12:16: note: while rewriting comparison as call to 'operator<=>'
declared here
constexpr auto operator<=>(bb bl, bb bm) { return bl.bf <=> bm.bf; }
^
1 warning generated.
```
Workspace for convenience: https://godbolt.org/z/5sxz4c
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs