https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122661

            Bug ID: 122661
           Summary: Incorrect value category handling in
                    forward_list::assign
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nedimsehic50 at gmail dot com
  Target Milestone: ---

#include <forward_list>

struct S {
    S() = default;
    S& operator=(S const&) & = delete;
    S& operator=(S const&) && { return *this; }
};

int main() {
    std::forward_list<S> l;
    S s;
    l.assign(&s, &s + 1);
}

Godbolt: https://godbolt.org/z/xKdMsxjcq

The above code does not compile with an error complaining about "use of deleted
function 'S& S::operator=(const S&) &'".
The problem is in this check in assign:

if constexpr (is_assignable<_Tp, decltype(*__first)>::value)

but then later there is

*__curr = *__first;

where __curr is an lvalue of type _Tp.

The fix would be to just replace _Tp with _Tp& inside the is_assignable check.

Reply via email to