Boost logo

Boost Users :

From: John McCabe (john_at_[hidden])
Date: 2022-01-12 10:42:58


On 12/01/2022 09:04, Alessio Mochi via Boost-users wrote:
> Hello Gavin,
> I have not defined BOOST_NO_EXCEPTIONS.

Interesting. The place where you're getting the compilation error is
within this section:

    #ifndef BOOST_NO_EXCEPTIONS
    #include <exception>
    #endif

    namespace boost {
    namespace serialization {

    #ifdef BOOST_NO_EXCEPTIONS

    BOOST_NORETURN inline void throw_exception(std::exception const & e) {
        ::boost::throw_exception(e);
    }

    #else

    template<class E> BOOST_NORETURN inline void throw_exception(E const
& e){
        throw e;
    }

    #endif

    } // namespace serialization
    } // namespace boost

so BOOST_NO_EXCEPTIONS must be getting declared somewhere, which is
borne out by the include list you provided not showing "exception" in
there (at least, not that I can see).

There is a declaration of boost::throw_exception in
<boost/throw_exception.hpp>, so adding that before your include of
<boost/serialization/throw_exception.hpp> may be appropriate to avoid
the compilation error, however that file includes the following code:

     namespace boost
     {

     #if defined( BOOST_NO_EXCEPTIONS )

     BOOST_NORETURN void throw_exception( std::exception const & e ); //
user defined
     BOOST_NORETURN void throw_exception( std::exception const & e,
boost::source_location const & loc ); // user defined

     #endif

where "user defined" sounds to me (not that I've used it, but..) like
you need to define your own implementations of those functions (or you
may end up with an undefined symbol error from the linker.

> I don't know why a small project with qt and boost serialization work
> and this one no. I tried to add #include <boost/exception/all.hpp>
> before include the serialization header,
> I don't know if it's correct but seem to fix the problem

all.hpp is as here -
https://www.boost.org/doc/libs/1_78_0/boost/exception/all.hpp, which
includes <boost/exception/exception.hpp>, where throw_exception is also
declared.

It's probably worth taking a look at this page:
https://www.boost.org/doc/libs/1_78_0/libs/throw_exception/doc/html/throw_exception.html
but also worth trying to track down where/why BOOST_NO_EXCEPTIONS is
defined if you think it's wrong.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net