[committed] libstdc++: Fix constraints on std::optional converting constructors [PR117889]

Message ID 20241203102045.259088-1-jwakely@redhat.com
State Committed
Commit 29bea6921d0e2e3dd20bc78926ef0e98b1b1e4ad
Headers
Series [committed] libstdc++: Fix constraints on std::optional converting constructors [PR117889] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Jonathan Wakely Dec. 3, 2024, 10:20 a.m. UTC
  The converting constructors had the same bug as the converting
assignments, so need the same fix as r15-5833-gc2c7d71eeeab7c.

libstdc++-v3/ChangeLog:

	PR libstdc++/117889
	PR libstdc++/117858
	* include/std/optional (optional(const optional<U>&)): Fix copy
	and paste error in constraints.
	(optional(optional<U>&&)): Likewise.
	* testsuite/20_util/optional/assignment/117858.cc: Move to ...
	* testsuite/20_util/optional/cons/117858.cc: New test.
---

The testcase from r15-5833-gc2c7d71eeeab7c now tests both construction
and assignment, so I've moved it to the cons dir.

Tested x86_64-linux. Pushed to trunk.

 libstdc++-v3/include/std/optional             |  4 ++--
 .../20_util/optional/assignment/117858.cc     | 17 --------------
 .../testsuite/20_util/optional/cons/117858.cc | 23 +++++++++++++++++++
 3 files changed, 25 insertions(+), 19 deletions(-)
 delete mode 100644 libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc
 create mode 100644 libstdc++-v3/testsuite/20_util/optional/cons/117858.cc
  

Patch

diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index 55e56cfb9ed..617e4418ad7 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -876,7 +876,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	: _Base(std::in_place, std::forward<_Up>(__t)) { }
 
       template<typename _Up>
-	requires (!is_same_v<optional, remove_cvref_t<_Up>>)
+	requires (!is_same_v<_Tp, _Up>)
 	  && is_constructible_v<_Tp, const _Up&>
 	  && __construct_from_contained_value<_Up>
 	constexpr explicit(!is_convertible_v<const _Up&, _Tp>)
@@ -888,7 +888,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
 
       template<typename _Up>
-	requires (!is_same_v<optional, remove_cvref_t<_Up>>)
+	requires (!is_same_v<_Tp, _Up>)
 	  && is_constructible_v<_Tp, _Up>
 	  && __construct_from_contained_value<_Up>
 	constexpr explicit(!is_convertible_v<_Up, _Tp>)
diff --git a/libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc b/libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc
deleted file mode 100644
index e7045b37dd9..00000000000
--- a/libstdc++-v3/testsuite/20_util/optional/assignment/117858.cc
+++ /dev/null
@@ -1,17 +0,0 @@ 
-// { dg-do compile { target c++17 } }
-
-// PR 117858 std::optional with a constructor template<typename T> ctor(T)
-
-#include <optional>
-
-struct Focus
-{
-  template<class T>
-  Focus(T newValue)  { }
-};
-
-void g(std::optional<Focus> f)
-{
-  f = f;
-  f = std::move(f);
-}
diff --git a/libstdc++-v3/testsuite/20_util/optional/cons/117858.cc b/libstdc++-v3/testsuite/20_util/optional/cons/117858.cc
new file mode 100644
index 00000000000..adb1bc7791c
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/optional/cons/117858.cc
@@ -0,0 +1,23 @@ 
+// { dg-do compile { target c++17 } }
+
+// PR 117858 std::optional with a constructor template<typename T> ctor(T)
+// PR 117889 Failure to build qtwebengine-6.8.1
+
+#include <optional>
+
+struct Focus
+{
+  template<class T> Focus(T) { }
+};
+
+void test_pr117858(std::optional<Focus>& f)
+{
+  f = f;
+  f = std::move(f);
+}
+
+void test_pr117889(std::optional<Focus>& f)
+{
+  std::optional<Focus> f2 = f;
+  std::optional<Focus> f3 = std::move(f);
+}