* [committed 1/3] libstdc++: Fix std::bad_expected_access constructor [PR105146]
@ 2022-04-08 17:38 Jonathan Wakely
2022-04-08 17:38 ` [committed 2/3] libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154] Jonathan Wakely
2022-04-08 17:38 ` [committed 3/3] libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153] Jonathan Wakely
0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Wakely @ 2022-04-08 17:38 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux, pushed to trunk.
-- >8 --
libstdc++-v3/ChangeLog:
PR libstdc++/105146
* include/std/expected (bad_expected_access): Move constructor
parameter.
* testsuite/20_util/expected/bad.cc: New test.
---
libstdc++-v3/include/std/expected | 2 +-
libstdc++-v3/testsuite/20_util/expected/bad.cc | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 libstdc++-v3/testsuite/20_util/expected/bad.cc
diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 39d07cda4a9..7b01a17fb57 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -95,7 +95,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
class bad_expected_access : public bad_expected_access<void> {
public:
explicit
- bad_expected_access(_Er __e) : _M_val(__e) { }
+ bad_expected_access(_Er __e) : _M_val(std::move(__e)) { }
// XXX const char* what() const noexcept override;
diff --git a/libstdc++-v3/testsuite/20_util/expected/bad.cc b/libstdc++-v3/testsuite/20_util/expected/bad.cc
new file mode 100644
index 00000000000..17bc6d69e88
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/expected/bad.cc
@@ -0,0 +1,15 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do compile }
+
+#include <expected>
+
+struct E {
+ E() = default;
+ E(E&&) = default;
+};
+
+void
+test_pr105146()
+{
+ std::bad_expected_access(E{});
+}
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [committed 2/3] libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154]
2022-04-08 17:38 [committed 1/3] libstdc++: Fix std::bad_expected_access constructor [PR105146] Jonathan Wakely
@ 2022-04-08 17:38 ` Jonathan Wakely
2022-04-08 17:38 ` [committed 3/3] libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153] Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2022-04-08 17:38 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux, pushed to trunk.
-- >8 --
libstdc++-v3/ChangeLog:
PR libstdc++/105154
* include/std/expected (expected<void, E>::swap): Set
_M_has_value to false for objects that previously had a value.
* testsuite/20_util/expected/swap.cc: Fix test to check void
specialization.
---
libstdc++-v3/include/std/expected | 2 ++
libstdc++-v3/testsuite/20_util/expected/swap.cc | 12 ++++++------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 7b01a17fb57..1864e866ed0 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -1104,6 +1104,7 @@ namespace __expected
std::construct_at(__builtin_addressof(_M_unex),
std::move(__x._M_unex)); // might throw
std::destroy_at(__builtin_addressof(__x._M_unex));
+ _M_has_value = false;
__x._M_has_value = true;
}
}
@@ -1115,6 +1116,7 @@ namespace __expected
std::move(_M_unex)); // might throw
std::destroy_at(__builtin_addressof(_M_unex));
_M_has_value = true;
+ __x._M_has_value = false;
}
else
{
diff --git a/libstdc++-v3/testsuite/20_util/expected/swap.cc b/libstdc++-v3/testsuite/20_util/expected/swap.cc
index 1b3b8c5f4e8..745db65fc6c 100644
--- a/libstdc++-v3/testsuite/20_util/expected/swap.cc
+++ b/libstdc++-v3/testsuite/20_util/expected/swap.cc
@@ -27,19 +27,19 @@ test_swap()
VERIFY( e3.error() == 4 );
VERIFY( e4.error() == 3 );
- std::expected<int, int> v1(1), v2(2);
- std::expected<int, int> v3(std::unexpect, 3), v4(std::unexpect, 4);
+ std::expected<void, int> v1, v2;
+ std::expected<void, int> v3(std::unexpect, 3), v4(std::unexpect, 4);
swap(v1, v2);
- VERIFY( v1.value() == 2 );
- VERIFY( v2.value() == 1 );
+ VERIFY( v1.has_value() );
+ VERIFY( v2.has_value() );
swap(v1, v3);
VERIFY( ! v1.has_value() );
VERIFY( v1.error() == 3 );
- VERIFY( v3.value() == 2 );
+ VERIFY( v3.has_value() );
swap(v1, v3);
VERIFY( ! v3.has_value() );
- VERIFY( v1.value() == 2 );
+ VERIFY( v1.has_value() );
VERIFY( v3.error() == 3 );
swap(v3, v4);
VERIFY( ! v3.has_value() );
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [committed 3/3] libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153]
2022-04-08 17:38 [committed 1/3] libstdc++: Fix std::bad_expected_access constructor [PR105146] Jonathan Wakely
2022-04-08 17:38 ` [committed 2/3] libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154] Jonathan Wakely
@ 2022-04-08 17:38 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2022-04-08 17:38 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux, pushed to trunk.
-- >8 --
libstdc++-v3/ChangeLog:
PR libstdc++/105153
* include/std/expected
(expected<void,E>::expected(expected<U,G>&&)): Fix constraints.
* testsuite/20_util/expected/cons.cc: Check constructor.
---
libstdc++-v3/include/std/expected | 4 ++--
.../testsuite/20_util/expected/cons.cc | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/expected b/libstdc++-v3/include/std/expected
index 1864e866ed0..3446d6dbaed 100644
--- a/libstdc++-v3/include/std/expected
+++ b/libstdc++-v3/include/std/expected
@@ -966,8 +966,8 @@ namespace __expected
}
template<typename _Up, typename _Gr>
- requires is_void_v<_Tp>
- && is_constructible_v<_Er, const _Gr&>
+ requires is_void_v<_Up>
+ && is_constructible_v<_Er, _Gr>
&& (!__cons_from_expected<_Up, _Gr>)
constexpr explicit(!is_convertible_v<_Gr, _Er>)
expected(expected<_Up, _Gr>&& __x)
diff --git a/libstdc++-v3/testsuite/20_util/expected/cons.cc b/libstdc++-v3/testsuite/20_util/expected/cons.cc
index 1fe5b7bf4d1..6946858198c 100644
--- a/libstdc++-v3/testsuite/20_util/expected/cons.cc
+++ b/libstdc++-v3/testsuite/20_util/expected/cons.cc
@@ -162,6 +162,22 @@ test_copy()
return true;
}
+constexpr bool
+test_pr105153()
+{
+ struct E {
+ E(int&&) = delete;
+ E(const int&);
+ };
+
+ std::expected<void, E> e(std::expected<void, int>{});
+
+ static_assert( ! std::is_constructible_v<std::expected<void, int>,
+ std::expected<int, int>> );
+
+ return true;
+}
+
int main()
{
test_default();
@@ -172,4 +188,6 @@ int main()
static_assert( test_err() );
test_copy();
static_assert( test_copy() );
+ test_pr105153();
+ static_assert( test_pr105153() );
}
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-08 17:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08 17:38 [committed 1/3] libstdc++: Fix std::bad_expected_access constructor [PR105146] Jonathan Wakely
2022-04-08 17:38 ` [committed 2/3] libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154] Jonathan Wakely
2022-04-08 17:38 ` [committed 3/3] libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153] Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).