https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If you change it to:
const int& aa = std::abs(a);
const int& foo=std::max(aa, aa);
You'll see that the problem goes away because the value returned by std::abs
gets its lifetime extended, then std::max returns a reference to the same
object, which has not gone out of scope.
Alternatively, avoid the pointless reference:
int foo = std::max(std::abs(a), std::abs(a));
