File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -854,7 +854,11 @@ 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" );
859863 new (&env_storage_) EnvType ();
860864 }
@@ -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)
Original file line number Diff line number Diff line change @@ -802,7 +802,11 @@ 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" );
807811 new (&env_storage_) EnvType ();
808812 }
@@ -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)
Original file line number Diff line number Diff line change 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,8 +21,12 @@ 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 ,
27+ " instance_storage_ does not meet the instance's alignment requirement" );
28+ static_assert (
29+ alignof (NoDestructor<InstanceType>) % alignof (InstanceType) == 0 ,
2530 " instance_storage_ does not meet the instance's alignment requirement" );
2631 new (&instance_storage_)
2732 InstanceType (std::forward<ConstructorArgTypes>(constructor_args)...);
@@ -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
You can’t perform that action at this time.
0 commit comments