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

            Bug ID: 88218
           Summary: Builtin for detecting that throw X will definitely
                    cause std::terminate
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

There's a need in a builtin like
__builtin_throw_will_terminate(exception_type);

Use cases include:
* Thread cancellation: detect that throwing a struct thread_cancel{}; will
cause a std::terminate. Useful for detecting that we're in the noexcept
descructor and the thread should not be cancelled in that place.
* Stackfull coroutine cancellation: same as above. Detect that throwing a
coroutine_cancel_exception does not cross a noexcept function boundaries.
* Algorithms with ExecutionPolicy - do not report errors via exceptions if
function is running in the std::seq/std::par/std::par_unseq algorithm.
* Assertions: assert from withing a particular throwing function that it is not
used from within the noexcept function.

The builtin could be implemented by investigating the exception tables at
runtime and detecting that throwing the exception will hit the std::terminate
case.

Reply via email to