https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61769
theemathas at hotmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #4 from theemathas at hotmail dot com ---
(In reply to Jonathan Wakely from comment #2)
> (In reply to theemathas from comment #1)
> > I am having some problems with uploading the "main.ii" file (apparently it
> > is too big because I #include 3 standard libraries). I am uploading the
> > non-preprocessed source code first, and I will upload the preprocessed code
> > ASAP.
>
> Don't bother, the program is invalid. std::abs returns a temporary that goes
> out of scope at the end of the expression, std::max returns a dangling
> reference to that temporary.
(In reply to Jonathan Wakely from comment #3)
> The for loop just causes the program to reuse the stack memory where the
> std::abs return slots were, so the memory where the dangling reference
> points gets modified and you see the value change.
I think my program is valid
According to http://en.cppreference.com/w/cpp/algorithm/max : std::max can
accept "const int&" as parameters
According to
http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/
: binding a temporary to a const reference "lengthens the lifetime of the
temporary to the lifetime of the reference itself"
Thus, no dangling reference.