https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81000
--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> --- (In reply to Marc Glisse from comment #2) > (Of course, a different implementation of std::any might be easier to > optimize) >From a quick test, if instead of storing a pointer to _S_manage we store a pointer to an array of function pointers (or a tuple so the types don't have to be identical) where each function does only one of the tasks (clone, xfer, etc), then with __attribute__(flatten) on f we manage to optimize to return 10. I am not claiming that would be a better implementation, it is the first time I take a look at std::any.