diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-03-31 12:17:02 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-03-31 17:12:26 +0100 |
commit | b9adf3a4c8112df1d74440157f578a8344ebe166 (patch) | |
tree | 60a4f0b23a38b07010fd227957a516b92dbc6846 | |
parent | c7eec82942496520d6b0604aa945a89f279e2562 (diff) | |
download | gcc-b9adf3a4c8112df1d74440157f578a8344ebe166.zip gcc-b9adf3a4c8112df1d74440157f578a8344ebe166.tar.gz gcc-b9adf3a4c8112df1d74440157f578a8344ebe166.tar.bz2 |
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 <tkaminsk@redhat.com>
-rw-r--r-- | libstdc++-v3/include/std/tuple | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index d3deb7b..2e69af1 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -2534,7 +2534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return [&]<size_t... _Inds>(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 0000000..3a65ef5 --- /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 <tuple> + +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<Object> t; + (void) (t == t); +} |