https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109440
--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> --- I believe that since v is constructed and passed by invisible refernece in the caller, we would need to know constructors of std::vector and prove that they do not make &v to escape to global memory, so foo can't access it. I sent patch that would enable us to optimize provided v is declared const.