]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix std::forward_list::assign assignable check [PR122661]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 13 Nov 2025 09:45:12 +0000 (09:45 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 13 Nov 2025 14:29:15 +0000 (14:29 +0000)
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.

libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/testsuite/23_containers/forward_list/modifiers/122661.cc [new file with mode: 0644]

index 8bcfb809319e22fabf48e927d3f9feae7cedb5ec..459b2f65ad1834b65ecd94d952e68ed747c8db9d 100644 (file)
@@ -1046,7 +1046,7 @@ namespace __fwdlist
        void
        assign(_InputIterator __first, _InputIterator __last)
        {
-         if constexpr (is_assignable<_Tp, decltype(*__first)>::value)
+         if constexpr (is_assignable<_Tp&, decltype(*__first)>::value)
            {
              auto __prev = before_begin();
              auto __curr = begin();
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 (file)
index 0000000..41ac32c
--- /dev/null
@@ -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);
+}