#1208·oneTBB

task_dispatcher.h calls 'do_throw_noexcept' without any TBB_USE_EXCEPTIONS guard

Author: GertyPCreated Sep 18, 2023Updated Aug 11, 2026
Labelsquestion

In 'task_dispatcher.h', local_wait_for_all, there's a call to do_throw_noexcept(...) - https://github.com/oneapi-src/oneTBB/blob/11545bd606be3187ffb3d7507c9ab21705123e61/src/tbb/task_dispatcher.h#L359

However, if the build has been configured with TBB_USE_EXCEPTIONS undefined (or defined to 0) then, in 'src/tbb/exception.cpp', the only implementations for do_throw_noexcept are entirely excluded from compling, resulting in a link error, referencing the undefined do_throw_noexcept symbol from within 'task_dispatcher.h'.

Since a throw from a noexcept function will result in a std::terminate() then, if TBB_USE_EXCEPTIONS is enabled, the code essentially becomes -

cpp
if (global_control::active_value(global_control::terminate_on_exception) == 1) {
    std::terminate();  // do_throw_noexcept([] { throw; });
}

But what would we want when TBB_USE_EXCEPTIONS is disabled? In both cases, it seems reasonable to simply directly call std::terminate() there; do_throw_noexcept([] { throw; }); seems just a slightly elaborate, round-about way of calling terminate. Is there a benefit to throwing from a noexcept func, over calling std::terminate()?