So here is what the docs say about -fnothrow-opt
:
Treat a throw() exception specification as if it were a noexcept specification to reduce or eliminate the text size overhead relative to a function with no exception specification. If the function has local variables of types with non-trivial destructors, the exception specification actually makes the function smaller because the EH cleanups for those variables can be optimized away. The semantic effect is that an exception thrown out of a function with such an exception specification results in a call to terminate rather than unexpected.
So, as I understand, the docs are mentioning dynamic exception specification or the throw() noexcept specifier. But both of these language elements have been removed (the dynamic exception specification in C++17 and the throw() noexcept specifier in C++20). So does that option have any effect when using newer C++ standards? The docs do not mention anything about it.
As it was explained in the comments to my question, -fnothrow-opt
has no effect. I think I could have figured it out from the description, but I just was a little confused. So, the docs say "Treat a throw() exception specification as if it were a noexcept specification", it states that there is a "throw() exception specification" and there is a different "noexcept specification", that means that yes, the option is talking about dynamic exception specification which was removed from C++. Also, the docs say "function with such an exception specification results in a call to terminate rather than unexpected", it mentions the unexpected function which was also removed from C++.
Additionally, I concluded that -fno-enforce-eh-specs
also has no effect when using newer C++ standards. Here is what the docs say about it:
Don’t generate code to check for violation of exception specifications at run time. This option violates the C++ standard, but may be useful for reducing code size in production builds, much like defining NDEBUG. This does not give user code permission to throw exceptions in violation of the exception specifications; the compiler still optimizes based on the specifications, so throwing an unexpected exception results in undefined behavior at run time.
Well, this runtime checking was a part of the dynamic exception specification and it is removed from C++ so we can conclude that this option also has no effect.