Build fails under clang-cl with C++20
- Dominant language
- C++
- Stars
- 495
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
On a Windows build using clang-cl, the build of `//riegeli/records/record_reader` fails with:
```
external/riegeli+/riegeli/records/record_reader.cc(651,9): error: call to 'BinarySearch' is ambiguous
651 | BinarySearch(
| ^~~~~~~~~~~~
external/riegeli+\riegeli/base/binary_search.h(375,26): note: candidate function [with Pos = unsigned long long, Test = (lambda at external/riegeli+/riegeli/records/record_reader.cc:653:13), $2 = 0]
375 | inline SearchResult BinarySearch(Pos low, Pos high, Test&& test) {
| ^
external/riegeli+\riegeli/base/binary_search.h(454,41): note: candidate function [with Pos = unsigned long long, Test = (lambda at external/riegeli+/riegeli/records/record_reader.cc:653:13), $2 = 0]
454 | inline std::optional> BinarySearch(Pos low, Pos high,
| ^
```
The call in question is here:
https://github.com/google/riegeli/blob/a5d3729931e19029a2a4171d89c6bf83654b1c3d/riegeli/records/record_reader.cc#L651
It has the signature:
```
BinarySearch(uint64_t, uint64_t, std::optional(uint64_t record_index));
```
But the compiler thinks it matches the plain overload:
https://github.com/google/riegeli/blob/a5d3729931e19029a2a4171d89c6bf83654b1c3d/riegeli/base/binary_search.h#L370-L375
As well as the `std::optional` one:
https://github.com/google/riegeli/blob/a5d3729931e19029a2a4171d89c6bf83654b1c3d/riegeli/base/binary_search.h#L449-L455
It should match the latter, the test returns `std::optional`, and that should match if `PartialOrdering` satisfies `IsOrdering`, which is defined as:
https://github.com/google/riegeli/blob/a5d3729931e19029a2a4171d89c6bf83654b1c3d/riegeli/base/compare.h#L67-L74
So it should match if all of `<`, `>`, and `==` are defined when the other arg is `0`. But if that applies to `T`, shouldn't it also apply to `std::optional`? It does seem like the way those comparison operators are derived differs in C++20, the other comparison operators for `std::optional` are derived from `<=>` starting in C++20. But I'm still very confused why the error is only coming up with clang-cl on Windows and not Clang on other platforms.
Contributor guide
Assessment
This issue has not been assessed yet.