https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104546
Bug ID: 104546 Summary: std::reference_wrapper doesn't compile with clang in some circumstances Product: gcc Version: 11.2.1 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <functional> #include <vector> #include <algorithm> int main() { std::function<bool(const int&, const int&)> comp = [](const int& a, const int& b) { return a < b; }; std::vector<int> vec; std::sort(vec.begin(), vec.end(), std::ref(comp)); // Doesn't compile } This fails with clang due to https://github.com/llvm/llvm-project/issues/53049 In file included from repro.cc:1: In file included from /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/functional:58: /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/refwrap.h:319:40: error: exception specification of 'function<__gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>, void>' uses itself = decltype(reference_wrapper::_S_fun(std::declval<_Up>()))> ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/refwrap.h:319:40: note: in instantiation of exception specification for 'function<__gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>, void>' requested here /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/refwrap.h:321:2: note: in instantiation of default argument for 'reference_wrapper<__gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>, void>' required here reference_wrapper(_Up&& __uref) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/type_traits:1017:57: note: while substituting deduced template arguments into function template 'reference_wrapper' [with _Up = __gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>, $1 = (no value), $2 = (no value)] = __bool_constant<__is_nothrow_constructible(_Tp, _Args...)>; ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/type_traits:1023:14: note: in instantiation of template type alias '__is_nothrow_constructible_impl' requested here : public __is_nothrow_constructible_impl<_Tp, _Args...>::type ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/type_traits:153:14: note: in instantiation of template class 'std::is_nothrow_constructible<__gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>, __gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>>' requested here : public conditional<_B1::value, _B2, _B1>::type ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/std_function.h:298:11: note: (skipping 7 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) return __and_<typename _Base::_Local_storage, ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_algo.h:1917:12: note: in instantiation of function template specialization 'std::__heap_select<__gnu_cxx::__normal_iterator<int *, std::vector<int>>, __gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>>' requested here std::__heap_select(__first, __middle, __last, __comp); ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_algo.h:1933:13: note: in instantiation of function template specialization 'std::__partial_sort<__gnu_cxx::__normal_iterator<int *, std::vector<int>>, __gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>>' requested here std::__partial_sort(__first, __last, __last, __comp); ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_algo.h:1954:9: note: in instantiation of function template specialization 'std::__introsort_loop<__gnu_cxx::__normal_iterator<int *, std::vector<int>>, long, __gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>>' requested here std::__introsort_loop(__first, __last, ^ /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_algo.h:4875:12: note: in instantiation of function template specialization 'std::__sort<__gnu_cxx::__normal_iterator<int *, std::vector<int>>, __gnu_cxx::__ops::_Iter_comp_iter<std::reference_wrapper<std::function<bool (const int &, const int &)>>>>' requested here std::__sort(__first, __last, __gnu_cxx::__ops::__iter_comp_iter(__comp)); ^ repro.cc:10:10: note: in instantiation of function template specialization 'std::sort<__gnu_cxx::__normal_iterator<int *, std::vector<int>>, std::reference_wrapper<std::function<bool (const int &, const int &)>>>' requested here std::sort(vec.begin(), vec.end(), std::ref(comp)); // Doesn't compile ^ 1 error generated. If possible we should try to workaround this.