https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103668
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #1) > I don't think this is valid C++. > > A vector created in a constexpr function must be destroyed there as well, it > cannot escape from the function. Not a C++ lawyer, but I think returning it from constexpr function is just fine, what is wrong is if it isn't destructed in the same constant evaluation as the construction. So the bug in the testcase IMHO is the constexpr keyword before auto vec = get_vector();, that means one constant evaluation is the computation of the initializer of vec and that doesn't destruct what it constructed. Now, if you remove that bogus constexpr keyword or replace it with const keyword, it works just fine, vec is constructed, vec.size() is computed and then vec is destructed.