<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - false positive -Wzero-as-null-pointer-constant involving spaceship operator"
href="https://bugs.llvm.org/show_bug.cgi?id=49008">49008</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>false positive -Wzero-as-null-pointer-constant involving spaceship operator
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mizvekov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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: <a href="https://godbolt.org/z/5sxz4c">https://godbolt.org/z/5sxz4c</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>