UB: reinterpret_cast pointer without using launder

Signed-off-by: wineway <wangyuweihx@gmail.com>
This commit is contained in:
wineway 2023-12-07 04:07:58 +08:00
parent 068d5ee1a3
commit e40943c945
3 changed files with 8 additions and 2 deletions

View File

@ -39,6 +39,12 @@
#endif // defined(DeleteFile)
#endif // defined(_WIN32)
#ifdef __cpp_lib_launder
#define LAUNDER(x) std::launder((x))
#else
#define LAUNDER(x) x
#endif
namespace leveldb {
class FileLock;

View File

@ -883,7 +883,7 @@ class SingletonEnv {
SingletonEnv(const SingletonEnv&) = delete;
SingletonEnv& operator=(const SingletonEnv&) = delete;
Env* env() { return reinterpret_cast<Env*>(&env_storage_); }
Env* env() { return LAUNDER(reinterpret_cast<Env*>(&env_storage_)); }
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)

View File

@ -778,7 +778,7 @@ class SingletonEnv {
SingletonEnv(const SingletonEnv&) = delete;
SingletonEnv& operator=(const SingletonEnv&) = delete;
Env* env() { return reinterpret_cast<Env*>(&env_storage_); }
Env* env() { return LAUNDER(reinterpret_cast<Env*>(&env_storage_)); }
static void AssertEnvNotInitialized() {
#if !defined(NDEBUG)