Compiler assistance with making a C++ codebase exception safe

Julian Waters via Gcc <[email protected]> Mon, 27 Jul 2026 02:02:09 +0800
Newsgroups gmane.comp.gcc.devel
Message-ID <CAP2b4GMiDA74ygCZXD2WO3hdp2f=sGfGQ7raTFRjkOrG+7ewXw@mail.gmail.com>
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.

best regards,
Julian