From: Jonathan Wakely Date: Mon, 31 Mar 2025 11:17:02 +0000 (+0100) Subject: libstdc++: Make operator== for std::tuple convert to bool [PR119545] X-Git-Tag: basepoints/gcc-16~484 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9adf3a4c8112df1d74440157f578a8344ebe166;p=thirdparty%2Fgcc.git libstdc++: Make operator== for std::tuple convert to bool [PR119545] The boolean-testable requirements don't require the type to be copyable, so we need to convert to bool before it might need to be copied. libstdc++-v3/ChangeLog: PR libstdc++/119545 * include/std/tuple (operator==): Convert comparison results to bool. * testsuite/20_util/tuple/comparison_operators/119545.cc: New test. Reviewed-by: Tomasz KamiƄski --- diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index d3deb7bc1241..2e69af13a98b 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -2534,7 +2534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return [&](index_sequence<_Inds...>) { // Fold == over the tuples until non-equal elements are found. - return ((std::get<_Inds>(__t) == std::get<_Inds>(__u)) && ...); + return (bool(std::get<_Inds>(__t) == std::get<_Inds>(__u)) && ...); }(index_sequence_for<_Tps...>{}); } diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc new file mode 100644 index 000000000000..3a65ef53b016 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc @@ -0,0 +1,24 @@ +// { dg-do compile { target c++11 } } +// Bug libstdc++/119545 +// tuple::operator==()'s help lambda does not specify return type as bool + +#include + +void +test_pr119545() +{ + struct Bool { + Bool() = default; + Bool(const Bool&) = delete; + operator bool() const { return true; } + }; + + static Bool b; + + struct Object { + const Bool& operator==(const Object&) const { return b; } + }; + + std::tuple t; + (void) (t == t); +}