{"id":2226785,"url":"http://patchwork.ozlabs.org/api/patches/2226785/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhupath8dc.gcc.gcc-TEST.tkaminsk.107.1.4@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.4@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T18:55:20","name":"[v1,04/13] Test for make_optional","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"756e7a8230f123b93eade207db620714190023d8","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.4@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/2226785/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226785/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 4g18y74cdBz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 05:52:15 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id DC2214494FF2\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 19:51:58 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 41E9D409BE99\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:56:23 +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 1FA22435B5\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 DC2214494FF2","OpenDKIM Filter v2.11.0 sourceware.org 41E9D409BE99"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 41E9D409BE99","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 41E9D409BE99","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776884183; cv=none;\n b=N/FGE6CZvL/ERcUagsIjziu1Kx8/isgogdIov4xH3CkszgatARvvbY4lFLpjbgmwM17xaV+V+mheOZTbm706dt62nJXNfSvbD555b+jjyFxriF4ivjT6gKKWmyx9qEz9JDeh1u1aoTavZC+uKL0NTeb+luyESYXHeW1S1pLuKs4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776884183; c=relaxed/simple;\n bh=OwRKTh3lZvc1b8hNeVWmrFPhvrJB48PPI5P5BbKMhPI=;\n h=From:Date:Subject:MIME-Version:To:Message-ID;\n b=CfE5UL5aPVYhMUIyuWGjeDKK1bpoQcXgUi/K1PYW2Kxiyg7bAdAhPA6zS+AVE+z00ZJj4Ug88FmGNVAjbgyBS9o8b4ofJ2zHuR3957Xu+qtj8KNorpisIp9Yatxs4Wo9L8vjVeYehAXwdrQPZC7kKPNdZAMFvZQf7wJ0xt1O4+0=","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:20 +0000","Subject":"[PATCH v1 04/13] Test for make_optional","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.4@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/32b485bde262a5212d756d8c3a2d201e018a6262","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             |  6 +-\n .../20_util/optional/make_optional_neg.cc     | 11 +++\n .../20_util/optional/ref/make_optional/1.cc   | 70 +++++++++++++++++++\n .../ref/make_optional/from_args_neg.cc        | 43 ++++++++++++\n .../ref/make_optional/from_lvalue_neg.cc      | 40 +++++++++++\n .../ref/make_optional/from_rvalue_neg.cc      | 38 ++++++++++\n 6 files changed, 205 insertions(+), 3 deletions(-)\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/make_optional_neg.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/ref/make_optional/1.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_args_neg.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_lvalue_neg.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_rvalue_neg.cc","diff":"diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional\nindex 581ff8e063c2..7572f231ff42 100644\n--- a/libstdc++-v3/include/std/optional\n+++ b/libstdc++-v3/include/std/optional\n@@ -2074,7 +2074,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t\toptional<decay_t<_Tp>>>\n     make_optional(_Tp&& __t)\n     noexcept(is_nothrow_constructible_v<optional<decay_t<_Tp>>, _Tp>)\n-    { return optional<decay_t<_Tp>>{ std::forward<_Tp>(__t) }; }\n+    { return optional<decay_t<_Tp>>( std::forward<_Tp>(__t) ); }\n \n   template<typename _Tp, typename... _Args>\n     constexpr\n@@ -2082,7 +2082,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t\toptional<_Tp>>\n     make_optional(_Args&&... __args)\n     noexcept(is_nothrow_constructible_v<_Tp, _Args...>)\n-    { return optional<_Tp>{ in_place, std::forward<_Args>(__args)... }; }\n+    { return optional<_Tp>( in_place, std::forward<_Args>(__args)... ); }\n \n   template<typename _Tp, typename _Up, typename... _Args>\n     constexpr\n@@ -2090,7 +2090,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t\toptional<_Tp>>\n     make_optional(initializer_list<_Up> __il, _Args&&... __args)\n     noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>)\n-    { return optional<_Tp>{ in_place, __il, std::forward<_Args>(__args)... }; }\n+    { return optional<_Tp>( in_place, __il, std::forward<_Args>(__args)... ); }\n \n   // Hash.\n \ndiff --git a/libstdc++-v3/testsuite/20_util/optional/make_optional_neg.cc b/libstdc++-v3/testsuite/20_util/optional/make_optional_neg.cc\nnew file mode 100644\nindex 000000000000..b7772fc9a59b\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/make_optional_neg.cc\n@@ -0,0 +1,11 @@\n+// { dg-do compile { target c++17 }  }\n+\n+#include <optional>\n+\n+struct S { int x; int* p; };\n+int v;\n+\n+auto os1 = std::make_optional<S>({1, &v}); // { dg-error \"no matching function for\" \"\" { target c++26 } }\n+\n+// { dg-prune-output \"no type named 'type' in 'struct std::enable_if\" }\n+// { dg-prune-output \"type/value mismatch at argument 1 in template parameter list\" }\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/1.cc b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/1.cc\nnew file mode 100644\nindex 000000000000..08a0df28b729\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/1.cc\n@@ -0,0 +1,70 @@\n+// { dg-do run { target c++20 }  }\n+\n+#include <optional>\n+#include <type_traits>\n+#include <testsuite_hooks.h>\n+\n+struct NonTrivial\n+{\n+  constexpr NonTrivial() {}\n+  constexpr NonTrivial(NonTrivial const&) {};\n+  constexpr ~NonTrivial() {};\n+};\n+\n+template<typename T>\n+struct Conv\n+{\n+  T t;\n+\n+  constexpr operator T() const noexcept\n+  { return t; }\n+};\n+\n+constexpr bool test()\n+{\n+  NonTrivial t;\n+  const NonTrivial& ct = t;\n+\n+#if __cplusplus > 202302\n+  auto o1 = std::make_optional<NonTrivial&>(t);\n+  VERIFY( o1.has_value() );\n+  VERIFY( &o1.value() == &t );\n+\n+  auto o2 = std::make_optional<const NonTrivial&>(t);\n+  VERIFY( o2.has_value() );\n+  VERIFY( &o2.value() == &t );\n+\n+  auto o3 = std::make_optional<const NonTrivial&>(ct);\n+  VERIFY( o3.has_value() );\n+  VERIFY( &o3.value() == &t );\n+\n+  Conv<NonTrivial&> rw(t);\n+  auto o4 = std::make_optional<NonTrivial&>(rw);\n+  VERIFY( o4.has_value() );\n+  VERIFY( &o4.value() == &t );\n+\n+  auto o5 = std::make_optional<NonTrivial&>(std::as_const(rw));\n+  VERIFY( o5.has_value() );\n+  VERIFY( &o5.value() == &t );\n+\n+  auto o6 = std::make_optional<NonTrivial&>(Conv<NonTrivial&>(t));\n+  VERIFY( o6.has_value() );\n+  VERIFY( &o6.value() == &t );\n+#else\n+  auto o1 = std::make_optional<NonTrivial&>(t);\n+  VERIFY( o1.has_value() );\n+  VERIFY( &o1.value() != &t );\n+\n+  auto o3 = std::make_optional<const NonTrivial&>(ct);\n+  VERIFY( o3.has_value() );\n+  VERIFY( &o3.value() != &t );\n+#endif\n+\n+  return true;\n+}\n+\n+int main()\n+{\n+  test();\n+  static_assert(test());\n+}\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_args_neg.cc b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_args_neg.cc\nnew file mode 100644\nindex 000000000000..6166c658c54b\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_args_neg.cc\n@@ -0,0 +1,43 @@\n+// { dg-do compile { target c++17 }  }\n+\n+#include <optional>\n+\n+struct C {\n+  C();\n+  C(int);\n+};\n+C s(10);\n+const C cs(1);\n+\n+template<typename T>\n+using decay_pre26 =\n+#if __cplusplus > 202302\n+  T;\n+#else\n+  std::decay_t<T>;\n+#endif\n+\n+auto z1 = std::make_optional<C&>();        // { dg-error \"no matching function for call\" }\n+auto z2 = std::make_optional<const C&>();  // { dg-error \"no matching function for call\" }\n+auto z3 = std::make_optional<C&&>();       // { dg-error \"no matching function for call\" }\n+auto z4 = std::make_optional<const C&&>(); // { dg-error \"no matching function for call\" }\n+\n+auto o1 = std::make_optional<C&>(10);        // { dg-error \"no matching function for call\" }\n+auto o2 = std::make_optional<const C&>(10);  // { dg-error \"from here\" }\n+auto o3 = std::make_optional<C&&>(10);       // { dg-error \"from here\" }\n+auto o4 = std::make_optional<const C&&>(10); // { dg-error \"from here\" }\n+\n+auto t1 = std::make_optional<C&>(10, 20);        // { dg-error \"no matching function for call\" }\n+auto t2 = std::make_optional<const C&>(10, 20);  // { dg-error \"no matching function for call\" }\n+auto t3 = std::make_optional<C&&>(10, 20);       // { dg-error \"no matching function for call\" }\n+auto t3 = std::make_optional<const C&&>(10, 20); // { dg-error \"no matching function for call\" }\n+\n+// { dg-prune-output \"no type named 'type' in 'struct std::enable_if\" }\n+// { dg-prune-output \"type/value mismatch at argument 1 in template parameter list\" }\n+// { dg-prune-output \"in a union may not have reference type\" }\n+// { dg-prune-output \"static assertion failed\" }\n+// { dg-prune-output \"forming pointer to reference type\" }\n+// { dg-prune-output \"cannot bind .* reference of type\" }\n+// { dg-prune-output \"binding reference of type\" }\n+// { dg-prune-output \"no matching function for call to 'std::optional\" }\n+\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_lvalue_neg.cc b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_lvalue_neg.cc\nnew file mode 100644\nindex 000000000000..0d6763735d85\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_lvalue_neg.cc\n@@ -0,0 +1,40 @@\n+// { dg-do compile { target c++17 }  }\n+\n+#include <optional>\n+#include <type_traits>\n+\n+struct C {\n+  C();\n+  C(int);\n+};\n+C s(10);\n+const C cs(1);\n+\n+template<typename T>\n+using decay_pre26 =\n+#if __cplusplus > 202302\n+  T;\n+#else\n+  std::decay_t<T>;\n+#endif\n+\n+auto lr1 = std::make_optional<C&>(s);        // changed meaning\n+static_assert( std::is_same_v< decltype(lr1), std::optional<decay_pre26<C&>>> );\n+auto lr2 = std::make_optional<const C&>(s);  // { dg-error \"here\" \"\" { target c++23_down } }\n+auto lr3 = std::make_optional<C&&>(s);       // { dg-error \"no matching function for call\" }\n+auto lr4 = std::make_optional<const C&&>(s); // { dg-error \"no matching function for call\" }\n+\n+auto clr1 = std::make_optional<C&>(cs);        // { dg-error \"no matching function for call\" }\n+auto clr2 = std::make_optional<const C&>(cs);  // changed meaning \n+static_assert( std::is_same_v< decltype(clr2), std::optional<decay_pre26<const C&>>> );\n+auto clr3 = std::make_optional<C&&>(cs);       // { dg-error \"no matching function for call\" }\n+auto clr3 = std::make_optional<const C&&>(cs); // { dg-error \"no matching function for call\" }\n+\n+// { dg-prune-output \"no type named 'type' in 'struct std::enable_if\" }\n+// { dg-prune-output \"type/value mismatch at argument 1 in template parameter list\" }\n+// { dg-prune-output \"in a union may not have reference type\" }\n+// { dg-prune-output \"static assertion failed\" }\n+// { dg-prune-output \"forming pointer to reference type\" }\n+// { dg-prune-output \"cannot bind .* reference of type\" }\n+// { dg-prune-output \"binding reference of type\" }\n+// { dg-prune-output \"no matching function for call to `std::optional\" }\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_rvalue_neg.cc b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_rvalue_neg.cc\nnew file mode 100644\nindex 000000000000..22f669ceb68e\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/ref/make_optional/from_rvalue_neg.cc\n@@ -0,0 +1,38 @@\n+// { dg-do compile { target c++17 }  }\n+\n+#include <optional>\n+#include <type_traits>\n+\n+struct C {\n+  C();\n+  C(int);\n+};\n+C s(10);\n+const C cs(1);\n+\n+template<typename T>\n+using decay_pre26 =\n+#if __cplusplus > 202302\n+  T;\n+#else\n+  std::decay_t<T>;\n+#endif\n+\n+auto p1 = std::make_optional<C&>(C(10));        // { dg-error \"no matching function for call\" }\n+auto p2 = std::make_optional<const C&>(C(10));  // { dg-error \"from here\" }\n+auto p3 = std::make_optional<C&&>(C(10));       // { dg-error \"from here\" \"\" { target c++26 } }\n+auto p4 = std::make_optional<const C&&>(C(10)); // { dg-error \"from here\" }\n+\n+auto b1 = std::make_optional<C&>({10});        // { dg-error \"no matching function for call\" }\n+auto b2 = std::make_optional<const C&>({10});  // { dg-error \"no matching function for call\" \"\" { target c++26 } }\n+auto b3 = std::make_optional<C&&>({10});       // { dg-error \"no matching function for call\" \"\" { target c++26 } }\n+auto b4 = std::make_optional<const C&&>({10}); // { dg-error \"no matching function for call\" \"\" { target c++26 } }\n+\n+// { dg-prune-output \"no type named 'type' in 'struct std::enable_if\" }\n+// { dg-prune-output \"type/value mismatch at argument 1 in template parameter list\" }\n+// { dg-prune-output \"in a union may not have reference type\" }\n+// { dg-prune-output \"static assertion failed\" }\n+// { dg-prune-output \"forming pointer to reference type\" }\n+// { dg-prune-output \"cannot bind .* reference of type\" }\n+// { dg-prune-output \"binding reference of type\" }\n+// { dg-prune-output \"no matching function for call to 'std::optional\" }\n","prefixes":["v1","04/13"]}