https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68912
Bug ID: 68912 Summary: Wrong value category used in _Bind functor Product: gcc Version: 4.9.4 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: --- From https://gcc.gnu.org/ml/libstdc++/2015-12/msg00035.html The _Bind class function-call operator looks something like this: template<typename... _Args, typename _Result = decltype( std::declval<_Functor>()(_Mu<_Bound_args>()( std::declval<_Bound_args&>(), std::declval<tuple<_Args...>&>() )... ) )> _Result operator()(_Args&&... __args) { ... } The problem is that std::declval returns an rvalue reference, but the functor is invoked in an lvalue context. As a result, the following (valid) code will fail to compile: #include<functional> struct B {}; struct C {}; struct A { B operator()(int, double, char) & { return B(); } C operator()(int, double, char) && {return C(); } }; int main() { A a; auto bound = std::bind(a, 5, 4.3, 'c'); auto res = bound(); }