Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by int_19h on Friday April 28, 2017 @01:03AM
(#14216971)
If goo doesn't throw, why not declare it nothrow?
Although I still don't see why, in your example, one of the variables cannot be elided even if goo does throw. Since there's no point at which address of r is taken, much less escapes the scope, it should always be safe to elide r and just return s, no?
For example the following code will compile differently depending on whether goo() can throw.
struct k { void p[4]; };
void goo(k s);
k foo() { k r; k s; goo(&s); r = s; return r; }
If goo() doesn't throw the extra variable s can be eliminated.