]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make operator== for std::tuple convert to bool [PR119545]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 31 Mar 2025 11:17:02 +0000 (12:17 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 31 Mar 2025 16:12:26 +0000 (17:12 +0100)
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>
libstdc++-v3/include/std/tuple
libstdc++-v3/testsuite/20_util/tuple/comparison_operators/119545.cc [new file with mode: 0644]

index d3deb7bc12411559f6fff7b8337dffc4709ddc98..2e69af13a98ba410ae54e0a00026e985784cc268 100644 (file)
@@ -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 (file)
index 0000000..3a65ef5
--- /dev/null
@@ -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);
+}