boostorg / serialization

Boost.org serialization module
http://boost.org/libs/serialization
119 stars 139 forks source link

Reverse include logic in throw_exception.hpp #315

Open gaspardpetit opened 3 months ago

gaspardpetit commented 3 months ago

I believe commit b4412f2867450aaecee1e91bf287ab34ebaf9168 by @jzmaddock introduced a bug in the include logic - the ifndef should have been changed for an ifdef. The fact that it has been there for 2 years without anyone complaining makes me doubt, so let me know what you think :D

See my note here: https://github.com/boostorg/serialization/commit/b4412f2867450aaecee1e91bf287ab34ebaf9168#r142878767

Essentially the code looks like this:

#ifndef BOOST_NO_EXCEPTIONS
#include <boost/throw_exception.hpp>
#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

We need the include when we are going to call ::boost::throw_exception(e); which gets called only when defined(BOOST_NO_EXCEPTIONS) is true. Therefore, it seems like the include should be on an ifdef rather than an ifndef.

jzmaddock commented 3 months ago

I think you're correct - my bad - the error has probably been hidden because almost everything in boost includes boost/throw_exception.hpp anyway!