https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61909
Bug ID: 61909 Summary: Small function optimization not applied to small objects Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lukeocamden at gmail dot com Seems like std::function only manages to avoid malloc for function pointers, but not for small objects. $ g++ --version g++ (GCC) 4.10.0 20140720 (experimental) Here's a test I ran on my Linux machine: #include <functional> extern "C" void* malloc(size_t) { abort(); } struct X { void operator()() { } }; void foo() { } int main() { std::function<void()> f1((static_cast<void (*)()>([]{}))); // OK std::function<void()> f2(foo); // OK std::function<void()> f3((X())); // abort std::function<void()> f4([]{}); // abort }