ned14 / outcome

Provides very lightweight outcome<T> and result<T> (non-Boost edition)
https://ned14.github.io/outcome
Other
676 stars 62 forks source link

Enable noexcept unit tests in Boost.Outcome, now exceptions globally disabled works in Boost.Exception #234

Open teajay-fr opened 3 years ago

teajay-fr commented 3 years ago

Compiling with BOOST_NO_EXCEPTIONS procuces the following output:

/home/bernard/CMakePackageCache/release/extern/Boost/1.73.0/baremetal-cortex-m0-gnu.9/Pkg/include/boost/throw_exception.hpp:180:84: error: no matching function for call to 'throw_exception(const char [24], boost::source_location)'
  180 | #define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x, BOOST_CURRENT_LOCATION)
      |                                                                                    ^
/home/bernard/CMakePackageCache/release/extern/Boost/1.73.0/baremetal-cortex-m0-gnu.9/Pkg/include/boost/outcome/experimental/../config.hpp:320:45: note: in expansion of macro 'BOOST_THROW_EXCEPTION'
  320 | #define BOOST_OUTCOME_THROW_EXCEPTION(expr) BOOST_THROW_EXCEPTION(expr)
      |                                             ^~~~~~~~~~~~~~~~~~~~~
/home/bernard/CMakePackageCache/release/extern/Boost/1.73.0/baremetal-cortex-m0-gnu.9/Pkg/include/boost/outcome/experimental/status_result.hpp:120:13: note: in expansion of macro 'BOOST_OUTCOME_THROW_EXCEPTION'
  120 |             BOOST_OUTCOME_THROW_EXCEPTION("wide value check failed");
teajay-fr commented 3 years ago

I've investigated a bit further and it seems that the BOOST version doesn't include the the tests for disabled exceptions. Running the tests from this repository showed that when exceptions are disabled every thing is fine.

teajay-fr commented 3 years ago

Further analysis showed that this version of outcome is OK. It's the boost implementation which has a problem.

To reproduce the error just add this following lines the test directory jam file:

 [ run tests/experimental-core-result-status.cpp : : : <rtti>off <exception-handling>off <define>BOOST_NO_RTTI <define>BOOST_NO_EXCEPTIONS ]

I think the outcome-status has the same issue.

ned14 commented 3 years ago

Boost.Exception fixed this in https://github.com/boostorg/exception/commit/330008445c38aa793a07909d623addfc885464e6, but it had to be reverted for the Boost 1.74 release last week. Now that is released, the fix is live. And Boost 1.75 will have it.

Standalone Outcome has worked fine on exceptions globally disabled for years now, if that helps.

Re: Enabling the noexcept tests in Boost.Outcome, that is a good idea now that is actually possible, and I will rename this issue accordingly. Thanks for the report!

apmanol commented 2 years ago

Hello,

trying to use boost::outcome in 1.75 but I can't compile without exceptions

c++ -DBOOST_ASIO_HEADER_ONLY -DBOOST_ASIO_NO_DEPRECATED -DBOOST_ASIO_NO_IOSTREAM -DBOOST_ERROR_CODE_HEADER_ONLY -DBOOST_NO_EXCEPTIONS  -O2 -g -DNDEBUG -fno-exceptions -std=gnu++17 
smi_message.cpp

In file included from /usr/include/boost/exception_ptr.hpp:9,
                 from /usr/include/boost/outcome/boost_result.hpp:37,
                 from /usr/include/boost/outcome/result.hpp:34,
                 from /usr/include/boost/outcome/outcome.hpp:34,
                 from /utils/smi_client/smi_client.hpp:8,
                 from /utils/smi_client/smi_message.cpp:14:
/usr/include/boost/exception/detail/exception_ptr.hpp:12:2: error: #error This header requires exception handling to be enabled.
   12 | #error This header requires exception handling to be enabled.

Do I miss some -Dflag to help skipping this #include ?

ned14 commented 2 years ago

@apmanol I vaguely remember it had to be reverted for the 1.75 release as well for some reason, but it's definitely working now. @zajo Can you tell us what might be happening here?

zajo commented 2 years ago

Try with the latest release please, let me know.

apmanol commented 2 years ago

Try with the latest release please, let me know.

Thank you very much for your prompt answers!

Unfortunately, the project toolchain has 1.75 version, so it's not possible to change/experiment with something different.

Anyway, I used the single header approach, that works as it should with -fno-exceptions.

zajo commented 2 years ago

The support for boost::exception_ptr under -fno-exceptions is a new thing, though I didn't take a note in which Boost release it was introduced.