Use volatile to make sure globals_retainer is not optimized away.

By using volatile qualifier for the internal member of the globals_retainer
class we ensure the constructor formally has observable behavior, which means
it cannot be optimized away.

Related to https://github.com/boostorg/filesystem/issues/217.
This commit is contained in:
Andrey Semashev 2021-11-23 02:01:37 +03:00
parent fa53749ac7
commit 04c6e582be

View File

@ -1568,9 +1568,9 @@ extern const init_func_ptr_t p_init_path_globals = &init_path_globals;
//! Makes sure the global initializer pointers are referenced and not removed by linker
struct globals_retainer
{
const init_func_ptr_t* const m_p_init_path_globals;
const init_func_ptr_t* volatile m_p_init_path_globals;
globals_retainer() : m_p_init_path_globals(&p_init_path_globals) {}
globals_retainer() { m_p_init_path_globals = &p_init_path_globals; }
};
BOOST_ATTRIBUTE_UNUSED
static const globals_retainer g_globals_retainer