What should happen in #cpp if an exception is thrown from a local variable destructor called after executing a return statement?
What if the exception is caught and a new value returned?
GCC/Clang doesn't destruct first return-value in both cases:https://wandbox.org/permlink/EYaWoDGVeYPvWf3H …
MSVC calls the destructor for the return-value in the first case, but not in the second. Is this a bug in three major compilers or am I just entering UB territory by throwing from a destructor?
-
-
For some context - I was wondering what the behaviour should be if an exception is thrown during destruction/cleanup of local state in a coroutine after a co_return. I thought it should be consistent with normal functions. Now I'm not so sure...
Prikaži ovu nit -
From the C++ WD [except.ctor]: > ... If an exception is thrown during the destruction of temporaries or local variables for a return statement, the destructor for the returned object (if any) is also invoked. ...
Prikaži ovu nit
Kraj razgovora
Novi razgovor -
-
-
I think it's a bug (and I thought we'd fixed it in clang, but apparently not). In any case, friends don't let friends write throwing destructors...
- Još 2 druga odgovora
Novi razgovor -
-
Destructors should not leak exceptions - you end up with partially destroyed objects. Having said that the MSVC “model” around exceptions and returned values is “strange”.
- Još 1 odgovor
Novi razgovor
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.