https://gcc.gnu.org/g:b9adf3a4c8112df1d74440157f578a8344ebe166

commit r15-9069-gb9adf3a4c8112df1d74440157f578a8344ebe166
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Mon Mar 31 12:17:02 2025 +0100

    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 <tkami...@redhat.com>

Diff:
---
 libstdc++-v3/include/std/tuple                     |  2 +-
 .../20_util/tuple/comparison_operators/119545.cc   | 24 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

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 [&]<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 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 <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);
+}

Reply via email to