File tree Expand file tree Collapse file tree 3 files changed +22
-12
lines changed Expand file tree Collapse file tree 3 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -854,9 +854,13 @@ class SingletonEnv {
854
854
#endif // !defined(NDEBUG)
855
855
static_assert (sizeof (env_storage_) >= sizeof (EnvType),
856
856
" 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 ,
858
862
" env_storage_ does not meet the Env's alignment needs" );
859
- new (& env_storage_) EnvType ();
863
+ new (env_storage_) EnvType ();
860
864
}
861
865
~SingletonEnv () = default ;
862
866
@@ -872,8 +876,7 @@ class SingletonEnv {
872
876
}
873
877
874
878
private:
875
- typename std::aligned_storage<sizeof (EnvType), alignof (EnvType)>::type
876
- env_storage_;
879
+ alignas (EnvType) char env_storage_[sizeof (EnvType)];
877
880
#if !defined(NDEBUG)
878
881
static std::atomic<bool > env_initialized_;
879
882
#endif // !defined(NDEBUG)
Original file line number Diff line number Diff line change @@ -802,9 +802,13 @@ class SingletonEnv {
802
802
#endif // !defined(NDEBUG)
803
803
static_assert (sizeof (env_storage_) >= sizeof (EnvType),
804
804
" 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 ,
806
810
" env_storage_ does not meet the Env's alignment needs" );
807
- new (& env_storage_) EnvType ();
811
+ new (env_storage_) EnvType ();
808
812
}
809
813
~SingletonEnv () = default ;
810
814
@@ -820,8 +824,7 @@ class SingletonEnv {
820
824
}
821
825
822
826
private:
823
- typename std::aligned_storage<sizeof (EnvType), alignof (EnvType)>::type
824
- env_storage_;
827
+ alignas (EnvType) char env_storage_[sizeof (EnvType)];
825
828
#if !defined(NDEBUG)
826
829
static std::atomic<bool > env_initialized_;
827
830
#endif // !defined(NDEBUG)
Original file line number Diff line number Diff line change 5
5
#ifndef STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
6
6
#define STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
7
7
8
+ #include < cstddef>
8
9
#include < type_traits>
9
10
#include < utility>
10
11
@@ -20,10 +21,14 @@ class NoDestructor {
20
21
explicit NoDestructor (ConstructorArgTypes&&... constructor_args) {
21
22
static_assert (sizeof (instance_storage_) >= sizeof (InstanceType),
22
23
" instance_storage_ is not large enough to hold the instance" );
24
+ static_assert (std::is_standard_layout_v<NoDestructor<InstanceType>>);
23
25
static_assert (
24
- alignof ( decltype ( instance_storage_)) >= alignof (InstanceType),
26
+ offsetof (NoDestructor, instance_storage_) % alignof (InstanceType) == 0 ,
25
27
" 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_)
27
32
InstanceType (std::forward<ConstructorArgTypes>(constructor_args)...);
28
33
}
29
34
@@ -37,8 +42,7 @@ class NoDestructor {
37
42
}
38
43
39
44
private:
40
- typename std::aligned_storage<sizeof (InstanceType),
41
- alignof (InstanceType)>::type instance_storage_;
45
+ alignas (InstanceType) char instance_storage_[sizeof (InstanceType)];
42
46
};
43
47
44
48
} // namespace leveldb
You can’t perform that action at this time.
0 commit comments