cppcoro icon indicating copy to clipboard operation
cppcoro copied to clipboard

Support -fno-exceptions

Open Qix- opened this issue 4 years ago • 1 comments

This is a request to support -fno-exceptions with exceptionless builds (via macro switch). In certain cases this is desirable behavior, namely for embedded and other environments that might use this library.

I did a quick sweep of the code and most cases where exception-related code appear can be switched out with an std::abort() call similar to the standard library's handling.

However, I did see some questionable usage: throw operation_cancelled{}. I've not used those facilities quite yet, but am I correct in assuming the exception here is being used for a non-exceptional control flow purpose? In which case, is there a better way to handle interruption events? Or does it also make sense to std::abort() here, too?

Qix- avatar Sep 26 '20 18:09 Qix-

Exploring this issue a bit, it seems that my initial assumption about operation_cancelled was correct; in a private fork I've added some CMake configuration to disable that set of functionality if exceptions are configured to be disabled.

I also had to add some macros in config.hpp that ultimately replace all usages of try, throw and catch with versions that either pass-through if exceptions are enabled or stub out the code if they are not (or std::abort() in the case of throw).

The combination of these two things seemed to work fine, but doctest turned into being a problem - firstly, you cannot test based on excepted signals (SIGABRT in our case), and it appears that there's some access protection violation in the signal handler when doctest attempts to construct an error message for the failed test (a cursory web search seems to suggest it's a clang-specific issue; I honestly have no idea how to debug what's going on there).

For now, I just added an #if !CPPCORO_NO_EXCEPTIONS check around the two tests (in task_tests.cpp and shared_task_tests.cpp) for the broken_promise test and all was well.

Otherwise, it seems to work OK if you don't need the cancellable facilities. We haven't tested it thorougly in the super-project but at least the tests run and pass.

Qix- avatar Sep 27 '20 04:09 Qix-