Merge bitcoin/bitcoin#31766: leveldb: pull upstream C++23 changes

c8fab356171a0e283d5716647e3243c04810ac51 ci: remove -Wno-error=deprecated-declarations from ASAN (fanquake)
a130bbd154d535b80fe9f602a13bf2e322817881 Squashed 'src/leveldb/' changes from 04b5790928..4188247086 (fanquake)

Pull request description:

  Cherry-picks two commits from upstream (302786e211, e829478c6a), which remove the usage of `std::aligned_storage/std::aligned_union`.

  Note the first cherry-pick is not clean, because due to Google tooling issues, it accidently contained a revert of the prior two commits. See https://github.com/google/leveldb/pull/1249 for more details.

  Also see https://issues.chromium.org/issues/388068052, although note that they [reverted the roll to latest leveldb](https://issues.chromium.org/issues/388068052#comment9). I'm guessing due to the acidental reversion issue above.

ACKs for top commit:
  l0rinc:
    ACK c8fab356171a0e283d5716647e3243c04810ac51
  darosior:
    ACK c8fab356171a0e283d5716647e3243c04810ac51 -- checked it's a clean subtree pull from https://github.com/bitcoin-core/leveldb-subtree/tree/bitcoin-fork
  dergoegge:
    utACK c8fab356171a0e283d5716647e3243c04810ac51

Tree-SHA512: 966e61b9ac88af5ae7bf71514bfd5bbdbd8c38c7af65feb6d5e4415062dcff5896dc33fe968ded3462cc599abd921d49ee8336db3e12ed3f59c91ceb949317b7
This commit is contained in:
merge-script 2025-03-20 13:03:52 +08:00
commit 7d76c9725c
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
4 changed files with 23 additions and 13 deletions

View File

@ -29,7 +29,7 @@ export BITCOIN_CONFIG="\
-DCMAKE_C_COMPILER=clang-${APT_LLVM_V} \
-DCMAKE_CXX_COMPILER=clang++-${APT_LLVM_V} \
-DCMAKE_C_FLAGS='-ftrivial-auto-var-init=pattern' \
-DCMAKE_CXX_FLAGS='-ftrivial-auto-var-init=pattern -Wno-error=deprecated-declarations' \
-DCMAKE_CXX_FLAGS='-ftrivial-auto-var-init=pattern' \
-DAPPEND_CXXFLAGS='-std=c++23' \
-DAPPEND_CPPFLAGS='-DARENA_DEBUG -DDEBUG_LOCKORDER' \
"

View File

@ -854,9 +854,13 @@ class SingletonEnv {
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
static_assert(
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
new (&env_storage_) EnvType();
new (env_storage_) EnvType();
}
~SingletonEnv() = default;
@ -872,8 +876,7 @@ class SingletonEnv {
}
private:
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
env_storage_;
alignas(EnvType) char env_storage_[sizeof(EnvType)];
#if !defined(NDEBUG)
static std::atomic<bool> env_initialized_;
#endif // !defined(NDEBUG)

View File

@ -802,9 +802,13 @@ class SingletonEnv {
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
static_assert(
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
new (&env_storage_) EnvType();
new (env_storage_) EnvType();
}
~SingletonEnv() = default;
@ -820,8 +824,7 @@ class SingletonEnv {
}
private:
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
env_storage_;
alignas(EnvType) char env_storage_[sizeof(EnvType)];
#if !defined(NDEBUG)
static std::atomic<bool> env_initialized_;
#endif // !defined(NDEBUG)

View File

@ -5,6 +5,7 @@
#ifndef STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
#define STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
#include <cstddef>
#include <type_traits>
#include <utility>
@ -20,10 +21,14 @@ class NoDestructor {
explicit NoDestructor(ConstructorArgTypes&&... constructor_args) {
static_assert(sizeof(instance_storage_) >= sizeof(InstanceType),
"instance_storage_ is not large enough to hold the instance");
static_assert(std::is_standard_layout_v<NoDestructor<InstanceType>>);
static_assert(
alignof(decltype(instance_storage_)) >= alignof(InstanceType),
offsetof(NoDestructor, instance_storage_) % alignof(InstanceType) == 0,
"instance_storage_ does not meet the instance's alignment requirement");
new (&instance_storage_)
static_assert(
alignof(NoDestructor<InstanceType>) % alignof(InstanceType) == 0,
"instance_storage_ does not meet the instance's alignment requirement");
new (instance_storage_)
InstanceType(std::forward<ConstructorArgTypes>(constructor_args)...);
}
@ -37,8 +42,7 @@ class NoDestructor {
}
private:
typename std::aligned_storage<sizeof(InstanceType),
alignof(InstanceType)>::type instance_storage_;
alignas(InstanceType) char instance_storage_[sizeof(InstanceType)];
};
} // namespace leveldb