Skip to content

Commit a9245e4

Browse files
committed
[libc++abi] Fix non-constant initialization of default terminate
handlers.
1 parent 72b41e6 commit a9245e4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

libcxxabi/src/cxa_default_handlers.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "include/atomic_support.h"
1919

2020
#if !defined(LIBCXXABI_SILENT_TERMINATE)
21+
22+
_LIBCPP_SAFE_STATIC
2123
static const char* cause = "uncaught";
2224

2325
__attribute__((noreturn))
@@ -82,21 +84,21 @@ static void demangling_unexpected_handler()
8284
std::terminate();
8385
}
8486

85-
static std::terminate_handler default_terminate_handler = demangling_terminate_handler;
86-
static std::terminate_handler default_unexpected_handler = demangling_unexpected_handler;
87+
static constexpr std::terminate_handler default_terminate_handler = demangling_terminate_handler;
88+
static constexpr std::terminate_handler default_unexpected_handler = demangling_unexpected_handler;
8789
#else
88-
static std::terminate_handler default_terminate_handler = ::abort;
89-
static std::terminate_handler default_unexpected_handler = std::terminate;
90+
static constexpr std::terminate_handler default_terminate_handler = ::abort;
91+
static constexpr std::terminate_handler default_unexpected_handler = std::terminate;
9092
#endif
9193

9294
//
9395
// Global variables that hold the pointers to the current handler
9496
//
9597
_LIBCXXABI_DATA_VIS
96-
std::terminate_handler __cxa_terminate_handler = default_terminate_handler;
98+
_LIBCPP_SAFE_STATIC std::terminate_handler __cxa_terminate_handler = default_terminate_handler;
9799

98100
_LIBCXXABI_DATA_VIS
99-
std::unexpected_handler __cxa_unexpected_handler = default_unexpected_handler;
101+
_LIBCPP_SAFE_STATIC std::unexpected_handler __cxa_unexpected_handler = default_unexpected_handler;
100102

101103
namespace std
102104
{

0 commit comments

Comments
 (0)