https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61909

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to lukeocamden from comment #2)
> (In reply to Jonathan Wakely from comment #1)
> > This is by design.
> 
> I don't really follow - do you mean a consequence of the design, or does the
> standard mandate copying/moving the object into the heap, or does using the
> heap have some other benefit?

None of the above.

I mean the author of our std::function intentionally chose to only avoid the
heap for function pointers

  /**
   *  Trait identifying "location-invariant" types, meaning that the
   *  address of the object (or any of its members) will not escape.
   *  Also implies a trivial copy constructor and assignment operator.
   */
  template<typename _Tp>
    struct __is_location_invariant
    : __or_<is_pointer<_Tp>, is_member_pointer<_Tp>>::type
    { };

...

    static const bool __stored_locally =
    (__is_location_invariant<_Functor>::value
     && sizeof(_Functor) <= _M_max_size
     && __alignof__(_Functor) <= _M_max_align
     && (_M_max_align % __alignof__(_Functor) == 0));

Reply via email to