Skip to content

Commit 6292352

Browse files
fanquakel0rinc
authored andcommitted
Squashed 'src/leveldb/' changes from 04b5790928..4188247086
4188247086 Merge bitcoin-core/leveldb-subtree#47: Fix C++23 compilation errors in leveldb 183e79a495 Fix speculatively some "placement new" issues in leveldb 82c31046ed Fix C++23 compilation errors in leveldb git-subtree-dir: src/leveldb git-subtree-split: 41882470862df219f74cdd38354007b91eb98191
1 parent e568c1d commit 6292352

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/leveldb/util/env_posix.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,13 @@ class SingletonEnv {
854854
#endif // !defined(NDEBUG)
855855
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
856856
"env_storage_ will not fit the Env");
857-
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
857+
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
858+
static_assert(
859+
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
860+
"env_storage_ does not meet the Env's alignment needs");
861+
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
858862
"env_storage_ does not meet the Env's alignment needs");
859-
new (&env_storage_) EnvType();
863+
new (env_storage_) EnvType();
860864
}
861865
~SingletonEnv() = default;
862866

@@ -872,8 +876,7 @@ class SingletonEnv {
872876
}
873877

874878
private:
875-
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
876-
env_storage_;
879+
alignas(EnvType) char env_storage_[sizeof(EnvType)];
877880
#if !defined(NDEBUG)
878881
static std::atomic<bool> env_initialized_;
879882
#endif // !defined(NDEBUG)

src/leveldb/util/env_windows.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,13 @@ class SingletonEnv {
802802
#endif // !defined(NDEBUG)
803803
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
804804
"env_storage_ will not fit the Env");
805-
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
805+
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
806+
static_assert(
807+
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
808+
"env_storage_ does not meet the Env's alignment needs");
809+
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
806810
"env_storage_ does not meet the Env's alignment needs");
807-
new (&env_storage_) EnvType();
811+
new (env_storage_) EnvType();
808812
}
809813
~SingletonEnv() = default;
810814

@@ -820,8 +824,7 @@ class SingletonEnv {
820824
}
821825

822826
private:
823-
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
824-
env_storage_;
827+
alignas(EnvType) char env_storage_[sizeof(EnvType)];
825828
#if !defined(NDEBUG)
826829
static std::atomic<bool> env_initialized_;
827830
#endif // !defined(NDEBUG)

src/leveldb/util/no_destructor.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
66
#define STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
77

8+
#include <cstddef>
89
#include <type_traits>
910
#include <utility>
1011

@@ -20,10 +21,14 @@ class NoDestructor {
2021
explicit NoDestructor(ConstructorArgTypes&&... constructor_args) {
2122
static_assert(sizeof(instance_storage_) >= sizeof(InstanceType),
2223
"instance_storage_ is not large enough to hold the instance");
24+
static_assert(std::is_standard_layout_v<NoDestructor<InstanceType>>);
2325
static_assert(
24-
alignof(decltype(instance_storage_)) >= alignof(InstanceType),
26+
offsetof(NoDestructor, instance_storage_) % alignof(InstanceType) == 0,
2527
"instance_storage_ does not meet the instance's alignment requirement");
26-
new (&instance_storage_)
28+
static_assert(
29+
alignof(NoDestructor<InstanceType>) % alignof(InstanceType) == 0,
30+
"instance_storage_ does not meet the instance's alignment requirement");
31+
new (instance_storage_)
2732
InstanceType(std::forward<ConstructorArgTypes>(constructor_args)...);
2833
}
2934

@@ -37,8 +42,7 @@ class NoDestructor {
3742
}
3843

3944
private:
40-
typename std::aligned_storage<sizeof(InstanceType),
41-
alignof(InstanceType)>::type instance_storage_;
45+
alignas(InstanceType) char instance_storage_[sizeof(InstanceType)];
4246
};
4347

4448
} // namespace leveldb

0 commit comments

Comments
 (0)