<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57208>57208</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Regression in call to `std::copy`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          JohelEGP
      </td>
    </tr>
</table>

<pre>
    See https://godbolt.org/z/PWEhj4Wds.
```C++
#include <algorithm>
#include <iterator>

template <class F>
class FunctionOutputIterator {
public:
    using difference_type = void;
    using iterator_category = std::output_iterator_tag;
    using pointer = void;
    using reference = void;
    using value_type = void;

    explicit FunctionOutputIterator(const F &action) : action_(action) {}
    explicit FunctionOutputIterator(F &&action) : action_(std::move(action)) {}

    template<class T, class = decltype(std::declval<F&>()(std::declval<T&&>()))>
    void operator=(T &&value)
    {
        action_(static_cast<T&&>(value));
    }

    FunctionOutputIterator &operator*() { return *this; }
    FunctionOutputIterator &operator++() { return *this; }
    FunctionOutputIterator &operator++(int) { return *this; }
private:
    F action_;
};

int main()
{
    auto lam = [](auto&& u) {
        u += 1;
    };
    FunctionOutputIterator f(lam);
    int a[10];
    std::copy(a, a+10, f);
}
```
```
<source>:32:11: error: no viable overloaded '+='
        u += 1;
        ~ ^  ~
<source>:16:40: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<const FunctionOutputIterator<(lambda at <source>:31:16)> &>' requested here
    template<class T, class = decltype(std::declval<F&>()(std::declval<T&&>()))>
                                       ^
<source>:17:10: note: in instantiation of default argument for 'operator=<const FunctionOutputIterator<(lambda at <source>:31:16)> &>' required here
    void operator=(T &&value)
         ^~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__type_traits/is_assignable.h:26:83: note: while substituting deduced template arguments into function template 'operator=' [with T = const FunctionOutputIterator<(lambda at <source>:31:16)> &, $1 = (no value)]
struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
                                                                                  ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__type_traits/is_copy_assignable.h:25:14: note: in instantiation of template class 'std::is_assignable<FunctionOutputIterator<(lambda at <source>:31:16)> &, const FunctionOutputIterator<(lambda at <source>:31:16)> &>' requested here
    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
             ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__utility/pair.h:265:25: note: in instantiation of template class 'std::is_copy_assignable<FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
                        is_copy_assignable<second_type>::value,
                        ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__algorithm/copy.h:92:25: note: in instantiation of template class 'std::pair<int *, FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) {
                        ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__algorithm/copy.h:103:15: note: in instantiation of function template specialization 'std::__copy<int *, int *, FunctionOutputIterator<(lambda at <source>:31:16)>, 0>' requested here
  return std::__copy(__first, __last, __result).second;
              ^
<source>:36:10: note: in instantiation of function template specialization 'std::copy<int *, FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
    std::copy(a, a+10, f);
         ^
<source>:32:11: error: no viable overloaded '+='
        u += 1;
        ~ ^  ~
<source>:16:40: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
    template<class T, class = decltype(std::declval<F&>()(std::declval<T&&>()))>
                                       ^
<source>:17:10: note: in instantiation of default argument for 'operator=<FunctionOutputIterator<(lambda at <source>:31:16)>>' required here
    void operator=(T &&value)
         ^~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__type_traits/is_assignable.h:26:83: note: while substituting deduced template arguments into function template 'operator=' [with T = FunctionOutputIterator<(lambda at <source>:31:16)>, $1 = (no value)]
struct _LIBCPP_TEMPLATE_VIS is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
                                                                                  ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__type_traits/is_move_assignable.h:26:14: note: in instantiation of template class 'std::is_assignable<FunctionOutputIterator<(lambda at <source>:31:16)> &, FunctionOutputIterator<(lambda at <source>:31:16)> &&>' requested here
    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
             ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__utility/pair.h:278:25: note: in instantiation of template class 'std::is_move_assignable<FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
                        is_move_assignable<second_type>::value,
                        ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__algorithm/copy.h:92:25: note: in instantiation of template class 'std::pair<int *, FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
pair<_InIter, _OutIter> __copy(_InIter __first, _Sent __last, _OutIter __result) {
                        ^
/opt/compiler-explorer/clang-trunk-20220817/bin/../include/c++/v1/__algorithm/copy.h:103:15: note: in instantiation of function template specialization 'std::__copy<int *, int *, FunctionOutputIterator<(lambda at <source>:31:16)>, 0>' requested here
  return std::__copy(__first, __last, __result).second;
              ^
<source>:36:10: note: in instantiation of function template specialization 'std::copy<int *, FunctionOutputIterator<(lambda at <source>:31:16)>>' requested here
    std::copy(a, a+10, f);
         ^
2 errors generated.
Compiler returned: 1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWtty4kYQ_RrxMmVKF4PggQfAkHJqU-vKkuyjapBGMJtBo2hGON6vT_doEALkWxZ7XRVUWlmXprvnnO5W98JSJg-jL4yRtda5coKx489hX8lkKYXuymIFV9_h393X2frb9ddEdR33xnHHTt-t9qnjT3Cv7voBz2JRJow4wZSKlSy4Xm-cYNb2nGtWUC2L_WNz1G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