kokkos / kokkos-core-wiki

3 stars 45 forks source link

Documentation of `ScopeGuard` seems misleading about unhandled exceptions #554

Closed JBludau closed 1 month ago

JBludau commented 3 months ago

It looks like if an unhandled exception makes it all the way up to main, the destructor of ScopeGuard is not called. Nevertheless, the documentation seems to promise exactly that.

ScopeGuard is a class which ensure thats Kokkos::initialize and Kokkos::finalize are called correctly even in the presence of unhandled exceptions.

But if the exception reaches main it seems to cause immediate termination of the program: https://godbolt.org/z/Pahs8MW3G

Furthermore, creating an unnamed ScopeGuard allows the compiler to call finalize immediately after initialize;

dalg24 commented 3 months ago

You're correct. The standard only guarantees that the destructors will be called if the exception is caught. https://eel.is/c++draft/except#ctor-1