[Bug c++/90516] Strange behaviour of code if function no return value and code embraced by try..catch with opt flags

2020-01-21 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90516

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|INVALID |DUPLICATE

--- Comment #2 from Andrew Pinski  ---


*** This bug has been marked as a duplicate of bug 86761 ***

[Bug c++/90516] Strange behaviour of code if function no return value and code embraced by try..catch with opt flags

2019-05-17 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90516

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #1 from Jonathan Wakely  ---
(In reply to matszpk from comment #0)
> I encountered that bug when I trying to test some program that have bug: a
> missing return in loading file function that code was embraced by
> try...catch. Due to this bug and enabled optimization's flags program aborts
> due to double free of the memory and it was strange behaviour of this
> function.

Because the program has a bug and its behaviour is undefined.

> Later, I wrote sample program that load some string from file and doing
> nothing this same bug (missing return) with code embraced by try..catch. If
> program was compiled with optimizations flags (-O3) then and if file was
> exist and then program print out exception in by statement in catch clause
> (just run clause) with like: 'Exception at loading: basic_ios::clear:
> iostream error'.

The program has undefined behaviour.

The only return statement in the function is the one in the catch block, so it
looks like GCC is deciding to run that code unconditionally, because there's no
other valid way to return from the function.

You should pay attention to the warning and fix the code.