Compiler assistance with making a C++ codebase exception safe

LIU Hao lh_mouse@126.com
Mon Jul 27 04:07:55 GMT 2026


在 2026-7-27 02:02, Julian Waters via Gcc 写道:
> Hi all,
> 
> C++ exceptions can be a problematic issue when trying to enable them
> on a codebase that used to be compiled with -fno-exceptions set.
> Mysterious compiler and linker errors that used to not be an issue
> will suddenly appear if you try to remove the flag, or worse,
> exceptions and exception handling can invisibly be inserted into the
> assembled code in places where you don't want them to be in. In my
> case the codebase I work on is rather large and frequently breaks when
> pulling commits from upstream for this very reason, and in the last
> working build when I looked inside the temporary files from the LTO
> link I found close to a thousand exception handlers inside it when
> none of the code uses exceptions or parts of the C++ Standard Library
> that throw, which optimizations seemingly cannot eliminate despite the
> use of LTO. Given how it can be rather difficult to see where exactly
> invisible exceptions and exception handling will appear implicitly in
> code, would a warning that shows any implicit exception handling in
> user code be worthwhile to implement, or is it just a silly idea? I
> imagine it would be useful for assisting in making a codebase
> exception safe when one has a desire to start using exceptions, where
> it would otherwise be nearly impossible due to implicit exceptions,
> though I don't know how easy this would be to implement, so I'm
> floating this idea here to see if it's a good one.

Would you try compiling with `-fnothrow-opt -fno-enforce-eh-specs` and see how much difference it makes?



-- 
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20260727/0c7d758f/attachment.sig>


More information about the Gcc mailing list