From cf9374933d2eacf91dae95e69082cba806f27c42 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Tue, 1 Jul 2025 15:41:24 +0200 Subject: [PATCH] [Modularize] Make `Location::operator bool` explicit This unbreaks C++20 buildbot that was broken since 402baea0a9ff7894565449e41f700c4e6a3f99cb. 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 402baea0a9ff7894565449e41f700c4e6a3f99cb, which ended up changing the comparisons results unintentionally. --- clang-tools-extra/modularize/Modularize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp index 1da531a4aefa..376ad0c7875b 100644 --- a/clang-tools-extra/modularize/Modularize.cpp +++ b/clang-tools-extra/modularize/Modularize.cpp @@ -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;