[Bug c++/61372] Add warning to detect noexcept functions that might throw

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 19 14:24:30 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61372

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to David Crocker from comment #5)
> You seem to be assuming that C++ exceptions can propagate through functions
> compiled with a C compiler.

I'm not assuming anything. I know for a fact that they can do so on some
platforms.

It is provably incorrect to say that extern "C" functions can't exit via an
exception. So it would be wrong to add a new warning which unconditionally
assumes extern "C" functions never throw.

> On most platforms, they normally cannot, because

Define most.

GCC supports it by default on many platforms.

> a C compiler does not produce the information needed for the C++ unwind
> mechanism to unwind the call stack. If you want bsearch and qsort to
> propagate C++ exceptions, on most platforms the implementations of those
> functions would have to be compiled either using a C++ compiler, or with a C
> compiler using a special option that tells the compiler to include the
> tables and/or code needed to propagate C++ exceptions. Otherwise the
> exception will end up at std::unexpected. Maybe bsearch and qsort in newlib
> are compiled this way, I haven't checked.

What has newlib got to do with anything? Are you asking for a new option that
only works when using newlib? Don't assume your use case is universal. New GCC
options need to consider a broad range of uses.

> I don't care whether extern "C" functions are to be assumed noexcept by
> default or another compiler option is needed to specify that. But without
> this facility, the proposed warning will be useless in practice, at least
> for people like me writing embedded software.

OK, so why do you keep arguing about it? What I said is it that treating extern
"C" functions as non-throwing needs to be optional. You've repeatedly argued
that my reasoning for that is bogus, based on "does it ever make sense to?" and
the answer is yes, sometimes it does.


More information about the Gcc-bugs mailing list