CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

gsl not_null throw exception

Open jonnygrant opened this issue 2 years ago • 1 comments

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr

Was throwing an exception considered? ie. std::logic_error or std::invalid_argument

Perhaps it is left implementation defined, as I can't spot a specific behavior described.

Presently GSL calls std::terminate(), quite a strong response. gsl-lite is the same.

An exception gives the application a chance to handle it (even if that was just gracefully logging). The user wouldn't be impacted by a std::terminate core dump SEGV; which is a bad outcome in a safety critical environment. Even worse in a library, we can't link to anything that might call std::terminate() like this in a safety critical environment; would be an uncontrolled program termination event.

Here is a one file example based on https://github.com/gsl-lite/gsl-lite

https://godbolt.org/z/Wdea6G9EW

This isn't production code, just an example.

jonnygrant avatar Sep 05 '23 20:09 jonnygrant

Related: #1561

shaneasd avatar Sep 08 '23 12:09 shaneasd