[Modularize] Make Location::operator bool explicit

This unbreaks C++20 buildbot that was broken since
402baea0a9.

With implicit conversion in C++20 compilation mode the spaceship
will unintentionally be based on `operator bool`:

```cpp
auto foo(Location L, Location R) {
  return L <=> R;
  // Equivalent to the following line due to implicit conversions.
  // return L.operator bool() <=> R.operator bool();
}
```

The spaceship operator is rarely used explicitly, but its implicit uses
in the STL may cause surprising results, as exposed by the use of  `std::tie`
in 402baea0a9, which ended up changing the
comparisons results unintentionally.
This commit is contained in:
Ilya Biryukov
2025-07-01 15:41:24 +02:00
parent d7b8b65e23
commit cf9374933d

View File

@@ -395,7 +395,7 @@ struct Location {
Column = SM.getColumnNumber(Decomposed.first, Decomposed.second);
}
operator bool() const { return File != nullptr; }
explicit operator bool() const { return File != nullptr; }
friend bool operator==(const Location &X, const Location &Y) {
return X.File == Y.File && X.Line == Y.Line && X.Column == Y.Column;