{"id":2226788,"url":"http://patchwork.ozlabs.org/api/patches/2226788/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.12@forge-stage.sourceware.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.12@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T18:55:28","name":"[v1,12/13] Test relops and hash","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1c15b2897576b47613ea150b7cc0c1c40bc6216b","submitter":{"id":93223,"url":"http://patchwork.ozlabs.org/api/people/93223/?format=json","name":"tkaminsk via Sourceware Forge","email":"forge-bot+tkaminsk@forge-stage.sourceware.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.12@forge-stage.sourceware.org/mbox/","series":[{"id":501097,"url":"http://patchwork.ozlabs.org/api/series/501097/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501097","date":"2026-04-22T18:55:20","name":"libstdc++: optional<T&> (P2988R12)","version":1,"mbox":"http://patchwork.ozlabs.org/series/501097/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226788/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226788/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org","sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org","server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g19133WjPz1yHB\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 05:54:47 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id A4B094858471\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 19:54:45 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 1F53C409FBB7\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:56:26 +0000 (GMT)","from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id 8EE42435BD\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:56:23 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org A4B094858471","OpenDKIM Filter v2.11.0 sourceware.org 1F53C409FBB7"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 1F53C409FBB7","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 1F53C409FBB7","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776884186; cv=none;\n b=OtzHe3xSjfJCMfMN/UdFCqiR1cq5tJHVrvS7/PPUE393Hf2JjFJP0J8sTbuiAoOP1giXz3FFenQDYnKC5MkPtunS7FzqOHusIjtIkFXJqlZgj5eDueMiXiTyFaABB6aPU/ZajZJBlvYl/YTJuquwkKj8yKF/YoM88r8AmCG5JVY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776884186; c=relaxed/simple;\n bh=kFeo/OPmp853n1g2HXO+bCsl4OHGdQX/90hzAEpvh34=;\n h=From:Date:Subject:MIME-Version:To:Message-ID;\n b=m9pUtRBNELzpaYU/cCyoTUNifmWJtoNZZ8xvq9sspOI2Lj0mXr+htBV/Za6Zw81r6sWtm8+zOVDLp1aOlgoFWNLGmrgtaiTDCnQovIudhSxNcdqLBxTrDmvNZCHsT3zZ507JQMKU/+/jLMtw60tdIqT0mX655go2E7H0xlyNdTU=","ARC-Authentication-Results":"i=1; server2.sourceware.org","From":"tkaminsk via Sourceware Forge\n <forge-bot+tkaminsk@forge-stage.sourceware.org>","Date":"Wed, 22 Apr 2026 18:55:28 +0000","Subject":"[PATCH v1 12/13] Test relops and hash","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.12@forge-stage.sourceware.org>","X-Mailer":"batrachomyomachia","X-Pull-Request-Organization":"gcc","X-Pull-Request-Repository":"gcc-TEST","X-Pull-Request":"https://forge.sourceware.org/gcc/gcc-TEST/pulls/107","References":"\n <bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.0@forge-stage.sourceware.org>","In-Reply-To":"\n <bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.0@forge-stage.sourceware.org>","X-Patch-URL":"\n https://forge.sourceware.org/tkaminsk/gcc/commit/e6cc0c5b473ea89eb1f496d7653de48af597026b","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>,\n tkaminsk@gcc.gnu.org","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"From: Tomasz Kamiński <tkaminsk@redhat.com>\n\n---\n libstdc++-v3/include/std/optional             |   1 +\n .../20_util/optional/ref/internal_traits.cc   |  11 +\n .../testsuite/20_util/optional/ref/relops.cc  | 229 ++++++++++++++++++\n 3 files changed, 241 insertions(+)\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/ref/internal_traits.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/ref/relops.cc","diff":"diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional\nindex 53d828f17b9b..2eb1678b35f1 100644\n--- a/libstdc++-v3/include/std/optional\n+++ b/libstdc++-v3/include/std/optional\n@@ -2115,6 +2115,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \n   template<typename _Tp>\n     struct hash<optional<_Tp>>\n+    // hash for optional<T&> is disabled because is_hash_enabled_for<T&> is false\n     : public __conditional_t<__is_hash_enabled_for<remove_const_t<_Tp>>,\n \t\t\t     __optional_hash<_Tp>,\n \t\t\t     __hash_not_enabled<_Tp>>\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/ref/internal_traits.cc b/libstdc++-v3/testsuite/20_util/optional/ref/internal_traits.cc\nnew file mode 100644\nindex 000000000000..ef50da7e9fa2\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/ref/internal_traits.cc\n@@ -0,0 +1,11 @@\n+// { dg-do compile { target c++26 }  }\n+\n+#include <optional>\n+#include <variant>\n+\n+template<typename T>\n+constexpr bool _Never_valueless\n+ = std::__detail::__variant::_Never_valueless_alt<T>::value;\n+\n+static_assert( _Never_valueless<std::optional<int&>> );\n+static_assert( _Never_valueless<std::optional<const int&>> );\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/ref/relops.cc b/libstdc++-v3/testsuite/20_util/optional/ref/relops.cc\nnew file mode 100644\nindex 000000000000..e0b30c8e898d\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/ref/relops.cc\n@@ -0,0 +1,229 @@\n+// { dg-do run { target c++26 }  }\n+\n+#include <optional>\n+#include <functional>\n+#include <testsuite_hooks.h>\n+#include <type_traits>\n+\n+template<typename T, typename H = std::hash<T>>\n+constexpr bool has_disabled_hash\n+ = !std::is_default_constructible_v<H>\n+ && !std::is_copy_constructible_v<H>\n+ && !std::is_move_constructible_v<H>\n+ && !std::is_copy_assignable_v<H>\n+ && !std::is_move_assignable_v<H>;\n+\n+static_assert(has_disabled_hash<std::optional<int&>>);\n+static_assert(has_disabled_hash<std::optional<const int&>>);\n+\n+template<typename T, typename V>\n+constexpr void\n+test_compare_val(V& l, V& h)\n+{\n+  std::optional<T> t;\n+\n+  VERIFY( !(t == l) );\n+  VERIFY(  (t != l) );\n+  VERIFY(  (t <  l) );\n+  VERIFY(  (t <= l) );\n+  VERIFY( !(t >  l) );\n+  VERIFY( !(t >= l) );\n+  VERIFY( (t <=> l) < 0 );\n+\n+  VERIFY( !(l == t) );\n+  VERIFY(  (l != t) );\n+  VERIFY( !(l <  t) );\n+  VERIFY( !(l <= t) );\n+  VERIFY(  (l >  t) );\n+  VERIFY(  (l >= t) );\n+  VERIFY( (l <=> t) > 0 );\n+\n+  t.emplace(l);\n+  VERIFY(  (t == l) );\n+  VERIFY( !(t != l) );\n+  VERIFY( !(t <  l) );\n+  VERIFY(  (t <= l) );\n+  VERIFY( !(t >  l) );\n+  VERIFY(  (t >= l) );\n+  VERIFY( (t <=> l) == 0 );\n+\n+  VERIFY(  (l == t) );\n+  VERIFY( !(l != t) );\n+  VERIFY( !(l <  t) );\n+  VERIFY(  (l <= t) );\n+  VERIFY( !(l >  t) );\n+  VERIFY(  (l >= t) );\n+  VERIFY( (t <=> l) == 0 );\n+\n+  t.emplace(h);\n+  VERIFY( !(t == l) );\n+  VERIFY(  (t != l) );\n+  VERIFY( !(t <  l) );\n+  VERIFY( !(t <= l) );\n+  VERIFY(  (t >  l) );\n+  VERIFY(  (t >= l) );\n+  VERIFY( (t <=> l) > 0 );\n+\n+  VERIFY( !(l == t) );\n+  VERIFY(  (l != t) );\n+  VERIFY(  (l <  t) );\n+  VERIFY(  (l <= t) );\n+  VERIFY( !(l >  t) );\n+  VERIFY( !(l >= t) );\n+  VERIFY( (l <=> t) < 0 );\n+}\n+\n+template<typename T, typename U, typename V>\n+constexpr void\n+test_compare_opts(V& l, V& h)\n+{\n+  std::optional<T> t;\n+  std::optional<U> u;\n+\n+  VERIFY(  (t == u) );\n+  VERIFY( !(t != u) );\n+  VERIFY( !(t <  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( !(t >  u) );\n+  VERIFY(  (t >= u) );\n+  VERIFY( (t <=> u) == 0 );\n+\n+  t.emplace(l);\n+  VERIFY( !(t == u) );\n+  VERIFY(  (t != u) );\n+  VERIFY( !(t <  u) );\n+  VERIFY( !(t <= u) );\n+  VERIFY(  (t >  u) );\n+  VERIFY(  (t >= u) );\n+  VERIFY( (t <=> u) > 0 );\n+\n+  u.emplace(l);\n+  VERIFY(  (t == u) );\n+  VERIFY( !(t != u) );\n+  VERIFY( !(t <  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( !(t >  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( (t <=> u) == 0 );\n+\n+  u.emplace(h);\n+  VERIFY( !(t == u) );\n+  VERIFY(  (t != u) );\n+  VERIFY(  (t <  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( !(t >  u) );\n+  VERIFY( !(t >= u) );\n+  VERIFY( (t <=> u) < 0 );\n+\n+  t.reset();\n+  u.emplace(l);\n+  VERIFY( !(t == u) );\n+  VERIFY(  (t != u) );\n+  VERIFY(  (t <  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( !(t >  u) );\n+  VERIFY( !(t >= u) );\n+  VERIFY( (t <=> u) < 0 );\n+\n+  t.emplace(h);\n+  VERIFY( !(t == u) );\n+  VERIFY(  (t != u) );\n+  VERIFY( !(t <  u) );\n+  VERIFY( !(t <= u) );\n+  VERIFY(  (t >  u) );\n+  VERIFY(  (t >= u) );\n+  VERIFY( (t <=> u) > 0 );\n+}\n+\n+template<typename V>\n+constexpr void\n+test_compare(V l, V h)\n+{\n+  test_compare_val<V&>(l, h);\n+  test_compare_val<const V&>(l, h);\n+\n+  test_compare_opts<V&, V&>(l, h);\n+  test_compare_opts<V, V&>(l, h);\n+  test_compare_opts<V&, V>(l, h);\n+\n+  test_compare_opts<const V&, const V&>(l, h);\n+  test_compare_opts<V, const V&>(l, h);\n+  test_compare_opts<const V&, V>(l, h);\n+\n+  test_compare_opts<V&, const V&>(l, h);\n+  test_compare_opts<const V&, V&>(l, h);\n+}\n+\n+struct TreeWay\n+{\n+  int v;\n+  friend auto operator<=>(TreeWay, TreeWay) = default;\n+};\n+\n+struct Other\n+{\n+  int v;\n+\n+  constexpr Other(int p) : v(p) {}\n+  constexpr Other(TreeWay p) : v(p.v) {}\n+\n+  friend bool operator==(Other, Other) = default;\n+  friend auto operator<=>(Other, Other) = default;\n+\n+  friend constexpr bool\n+  operator==(const Other& lhs, const TreeWay& rhs)\n+  { return lhs.v == rhs.v; }\n+\n+  friend constexpr std::strong_ordering\n+  operator<=>(const Other& lhs, const TreeWay& rhs)\n+  { return lhs.v <=> rhs.v; }\n+};\n+\n+constexpr void\n+test_heterogeneus_cmp()\n+{\n+  TreeWay l{10};\n+  Other h{20};\n+\n+  std::optional<TreeWay&> t;\n+  std::optional<const Other&> u;\n+\n+  VERIFY(  (t == u) );\n+  VERIFY( !(t != u) );\n+  VERIFY( !(t <  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( !(t >  u) );\n+  VERIFY(  (t >= u) );\n+  VERIFY( (t <=> u) == 0 );\n+\n+  t.emplace(l);\n+  VERIFY( !(t == u) );\n+  VERIFY(  (t != u) );\n+  VERIFY( !(t <  u) );\n+  VERIFY( !(t <= u) );\n+  VERIFY(  (t >  u) );\n+  VERIFY(  (t >= u) );\n+  VERIFY( (t <=> u) > 0 );\n+\n+  u.emplace(h);\n+  VERIFY( !(t == u) );\n+  VERIFY(  (t != u) );\n+  VERIFY(  (t <  u) );\n+  VERIFY(  (t <= u) );\n+  VERIFY( !(t >  u) );\n+  VERIFY( !(t >= u) );\n+  VERIFY( (t <=> u) < 0 );\n+}\n+\n+int main()\n+{\n+  auto test_all = [] {\n+    test_compare(2, 5);\n+    test_compare(TreeWay{11}, TreeWay{12});\n+    test_heterogeneus_cmp();\n+    return true;\n+  };\n+\n+  test_all();\n+  static_assert(test_all());\n+}\n","prefixes":["v1","12/13"]}