[Bug c++/61597] Unexpected behavior at runtime
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jun 25 13:23:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61597
--- Comment #17 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #16)
> Marc:
>
> struct Iter
> {
> Iter& operator+=(int) { return *this; }
>
> int operator*() { return i; }
>
> int i;
> };
>
> Iter& func(Iter iter, int n) {
> return iter += n;
> }
>
> int main()
> {
> Iter iter = Iter();
> Iter it = func(iter, 2);
> return *it;
> }
Thanks, I only need to add to my patch:
|| TREE_CODE (valbase) == PARM_DECL
in find_explicit_erroneous_behaviour and it warns for this at -O2. I was only
handling local variables and not parameters. I'll have to check if returning
the address of a PARM_DECL is always wrong. And if func is inline, it will
require -fkeep-inline-functions.
e.cc: In function 'Iter& func(Iter, int)':
e.cc:11:20: warning: function returns address of local variable
[-Wreturn-local-addr]
return iter += n;
^
e.cc:10:17: note: declared here
Iter& func(Iter iter, int n) {
^
More information about the Gcc-bugs
mailing list