Skip to content

Commit c229237

Browse files
committed
Provide boost::throw_exception compiled definition for MSVC
No Boost compiled library contains throw_exception — not even libboost_exception.lib (verified via dumpbin: only has clone_current_exception). MSVC pre-compiled Boost libraries reference the non-template overloads which GCC/Clang resolve from headers but MSVC requires as compiled symbols. This is Boost's intended design for non-header-only builds — user provides the implementation.
1 parent 734dae2 commit c229237

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(source
3333
address_utils.hpp address_utils.cpp
3434
leveldb_store.hpp leveldb_store.cpp
3535
address_validator.hpp address_validator.cpp
36+
boost_throw_exception.cpp
3637
)
3738

3839
find_package(yaml-cpp REQUIRED)

src/core/boost_throw_exception.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Compiled implementation of boost::throw_exception for Boost 1.90+.
2+
//
3+
// Boost's throw_exception.hpp declares non-template overloads:
4+
// void throw_exception(std::exception const&);
5+
// void throw_exception(std::exception const&, source_location const&);
6+
// but no Boost compiled library provides the definition — not even
7+
// libboost_exception (which only has clone_current_exception).
8+
// The user is expected to provide these when not using BOOST_NO_EXCEPTIONS
9+
// in header-only mode. On GCC/Clang, the template overloads in the header
10+
// satisfy all call sites. On MSVC, the non-template symbols are referenced
11+
// by pre-compiled Boost libraries (log, thread, filesystem), requiring
12+
// this compiled definition.
13+
14+
#include <boost/version.hpp>
15+
#if BOOST_VERSION >= 109000
16+
17+
#include <boost/config.hpp>
18+
#include <boost/throw_exception.hpp>
19+
20+
namespace boost {
21+
22+
BOOST_NORETURN void throw_exception(std::exception const& e) {
23+
throw e;
24+
}
25+
26+
BOOST_NORETURN void throw_exception(std::exception const& e,
27+
boost::source_location const&) {
28+
throw e;
29+
}
30+
31+
} // namespace boost
32+
33+
#endif

0 commit comments

Comments
 (0)