From ba202718c7149bd449d8a9cc11d1e976a6e31366 Mon Sep 17 00:00:00 2001 From: Isaac Garzon Date: Thu, 14 Jul 2022 13:29:48 +0300 Subject: [PATCH] customizable_test: revert the offsetof() build-related fixes (#55) They were made because the original version failed to compile with Clang 12 and 13, complaining about `offsetof()` being applied to a non-standard-layout type. The error is no longer emitted with Clang 14, so this is likely a compiler bug that was fixed, and there's no need for this dirty hack. --- options/customizable_test.cc | 59 ++++++++++++------------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/options/customizable_test.cc b/options/customizable_test.cc index d3c9ea9055..2447f60041 100644 --- a/options/customizable_test.cc +++ b/options/customizable_test.cc @@ -9,11 +9,9 @@ #include "rocksdb/customizable.h" -#include #include #include #include -#include #include #include "db/db_test_util.h" @@ -210,49 +208,32 @@ struct SimpleOptions { TestCustomizable* cp = nullptr; }; -static std::unordered_map simple_option_info; - -template -static int dynamic_unsafe_offsetof(const T& instance, const F& field) { - const char* instance_addr = - reinterpret_cast(std::addressof(instance)); - const char* field_addr = reinterpret_cast(std::addressof(field)); - assert(field_addr >= instance_addr); - const size_t offset = field_addr - instance_addr; - assert(offset < sizeof(instance)); - return offset; -} +static std::unordered_map simple_option_info = { +#ifndef ROCKSDB_LITE + {"bool", + {offsetof(struct SimpleOptions, b), OptionType::kBoolean, + OptionVerificationType::kNormal, OptionTypeFlags::kNone}}, + {"unique", + OptionTypeInfo::AsCustomUniquePtr( + offsetof(struct SimpleOptions, cu), OptionVerificationType::kNormal, + OptionTypeFlags::kAllowNull)}, + {"shared", + OptionTypeInfo::AsCustomSharedPtr( + offsetof(struct SimpleOptions, cs), OptionVerificationType::kNormal, + OptionTypeFlags::kAllowNull)}, + {"pointer", + OptionTypeInfo::AsCustomRawPtr( + offsetof(struct SimpleOptions, cp), OptionVerificationType::kNormal, + OptionTypeFlags::kAllowNull)}, +#endif // ROCKSDB_LITE +}; class SimpleConfigurable : public Configurable { private: SimpleOptions simple_; public: - SimpleConfigurable() { -#ifndef ROCKSDB_LITE - SimpleOptions so; - simple_option_info.emplace( - "bool", OptionTypeInfo{ - dynamic_unsafe_offsetof(so, so.b), OptionType::kBoolean, - OptionVerificationType::kNormal, OptionTypeFlags::kNone}); - simple_option_info.emplace( - "unique", - OptionTypeInfo::AsCustomUniquePtr( - dynamic_unsafe_offsetof(so, so.cu), OptionVerificationType::kNormal, - OptionTypeFlags::kAllowNull)); - simple_option_info.emplace( - "shared", - OptionTypeInfo::AsCustomSharedPtr( - dynamic_unsafe_offsetof(so, so.cs), OptionVerificationType::kNormal, - OptionTypeFlags::kAllowNull)); - simple_option_info.emplace( - "pointer", - OptionTypeInfo::AsCustomRawPtr( - dynamic_unsafe_offsetof(so, so.cp), OptionVerificationType::kNormal, - OptionTypeFlags::kAllowNull)); -#endif // ROCKSDB_LITE - RegisterOptions(&simple_, &simple_option_info); - } + SimpleConfigurable() { RegisterOptions(&simple_, &simple_option_info); } explicit SimpleConfigurable( const std::unordered_map* map) {