outcome icon indicating copy to clipboard operation
outcome copied to clipboard

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

Open teajay-fr opened this issue 5 years ago • 8 comments

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 avatar Aug 19 '20 08:08 teajay-fr

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 avatar Aug 19 '20 09:08 teajay-fr

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.

teajay-fr avatar Aug 19 '20 09:08 teajay-fr

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!

ned14 avatar Aug 19 '20 10:08 ned14

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 ?

apmanol avatar Mar 22 '22 07:03 apmanol

@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?

ned14 avatar Mar 22 '22 13:03 ned14

Try with the latest release please, let me know.

zajo avatar Mar 22 '22 16:03 zajo

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.

apmanol avatar Mar 23 '22 13:03 apmanol

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.

zajo avatar Mar 23 '22 19:03 zajo