Sự cố này xuất phát từ this question.Hành vi khác nhau giữa libstdC++ và libC++ khi xây dựng std :: function with lambda
Các mã sau đây compiles fine sử dụng kêu vang 3.4 với libstdC++:
#include <functional>
int main() {
std::function<void()> f = []() {};
}
Nhưng fails miserably sử dụng kêu vang 3.4 và libC++:
In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:320:11: error: rvalue reference to type '<lambda at main.cpp:4:31>' cannot bind to lvalue of type '<lambda at main.cpp:4:31>'
: value(__t.get())
^ ~~~~~~~~~
/usr/include/c++/v1/tuple:444:8: note: in instantiation of member function 'std::__1::__tuple_leaf<0, <lambda at main.cpp:4:31> &&, false>::__tuple_leaf' requested here
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
^
/usr/include/c++/v1/functional:1278:26: note: in instantiation of member function 'std::__1::__function::__func<<lambda at main.cpp:4:31>, std::__1::allocator<<lambda at main.cpp:4:31> >, void()>::__func' requested here
::new (__f_) _FF(_VSTD::move(__f));
^
main.cpp:4:31: note: in instantiation of function template specialization 'std::__1::function<void()>::function<<lambda at main.cpp:4:31> >' requested here
std::function<void()> f = []() {};
^
In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:321:10: error: static_assert failed "Can not copy a tuple with rvalue reference member"
{static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/tuple:320:11: error: rvalue reference to type 'allocator<[...]>' cannot bind to lvalue of type 'allocator<[...]>'
: value(__t.get())
^ ~~~~~~~~~
/usr/include/c++/v1/tuple:444:8: note: in instantiation of member function 'std::__1::__tuple_leaf<0, std::__1::allocator<<lambda at main.cpp:4:31> > &&, false>::__tuple_leaf' requested here
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
^
/usr/include/c++/v1/functional:1286:34: note: in instantiation of member function 'std::__1::__function::__func<<lambda at main.cpp:4:31>, std::__1::allocator<<lambda at main.cpp:4:31> >, void()>::__func' requested here
::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
^
main.cpp:4:31: note: in instantiation of function template specialization 'std::__1::function<void()>::function<<lambda at main.cpp:4:31> >' requested here
std::function<void()> f = []() {};
^
In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:321:10: error: static_assert failed "Can not copy a tuple with rvalue reference member"
{static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
Những hành vi là đúng?
Vâng, một khi đã giảm xuống dạng '[]() {}', hành vi đúng là khá rõ ràng. Cảm ơn bạn đã liên kết đến báo cáo lỗi. –