Skip to content

Commit cf93749

Browse files
committed
[Modularize] Make Location::operator bool explicit
This unbreaks C++20 buildbot that was broken since 402baea. 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 402baea, which ended up changing the comparisons results unintentionally.
1 parent d7b8b65 commit cf93749

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang-tools-extra/modularize/Modularize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ struct Location {
395395
Column = SM.getColumnNumber(Decomposed.first, Decomposed.second);
396396
}
397397

398-
operator bool() const { return File != nullptr; }
398+
explicit operator bool() const { return File != nullptr; }
399399

400400
friend bool operator==(const Location &X, const Location &Y) {
401401
return X.File == Y.File && X.Line == Y.Line && X.Column == Y.Column;

0 commit comments

Comments
 (0)