summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-11-13 09:45:12 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2025-11-14 01:23:52 +0000
commitec30d56ed6a02cb84e5a153b7e69fc14695772ae (patch)
tree88b09248fcd957a4580b8f544edebfbea1c7f48a
parent2af9a55d606c7c11b2461423a343fe66719b726c (diff)
libstdc++: Fix std::forward_list::assign assignable check [PR122661]
The std::is_assignable check should test for assignment to an lvalue, not an rvalue. libstdc++-v3/ChangeLog: PR libstdc++/122661 * include/bits/forward_list.h (forward_list::assign(I, I)): Fix value category in is_assignable check. * testsuite/23_containers/forward_list/modifiers/122661.cc: New test. (cherry picked from commit 9332dfd4523ddb100668a7c11a144a2bd676da7e)
-rw-r--r--libstdc++-v3/include/bits/forward_list.h2
-rw-r--r--libstdc++-v3/testsuite/23_containers/forward_list/modifiers/122661.cc20
2 files changed, 21 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h
index 72b1ef46d14..81e18767803 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -669,7 +669,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
void
assign(_InputIterator __first, _InputIterator __last)
{
- typedef is_assignable<_Tp, decltype(*__first)> __assignable;
+ typedef is_assignable<_Tp&, decltype(*__first)> __assignable;
_M_assign(__first, __last, __assignable());
}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/122661.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/122661.cc
new file mode 100644
index 00000000000..41ac32c7ec6
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/122661.cc
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++11 } }
+
+// Bug 122661 - Incorrect value category handling in forward_list::assign
+
+#include <forward_list>
+
+struct S
+{
+ S();
+ S& operator=(S const&) & = delete;
+ S& operator=(S const&) &&;
+};
+
+void
+test_pr122661()
+{
+ std::forward_list<S> fl;
+ S* iter = nullptr;
+ fl.assign(iter, iter);
+}