3 ms·
Just to help bring things home: const int& f(int parameter) { return parameter; } const int i = f(42); Is strictly undefined behavior under the simpler C+
by MaulingMonkey 10y ago
Just to help bring things home:
const int& f(int parameter) { return parameter; }
const int i = f(42);
Is strictly undefined behavior under the simpler C++03 rules/wording of 5.2.2/4: "The lifetime of a parameter ends when the function in which it is defined returns.")
P0135R0 would loosen the requirements on parameter's lifetime as a means of enabling guaranteed copy elision, in such a way that an implementation could technically decide to make this to have defined behavior (not that I suggest relying on it!)