From 916ab0195d567fd0a9097045e73a6654c453adea Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Wed, 3 Mar 2021 01:42:24 +0100 Subject: [PATCH] remove unused class util::Ref and its unit test --- src/Makefile.am | 1 - src/Makefile.test.include | 1 - src/test/ref_tests.cpp | 33 ------------------------- src/util/ref.h | 38 ----------------------------- test/lint/extended-lint-cppcheck.sh | 1 - 5 files changed, 74 deletions(-) delete mode 100644 src/test/ref_tests.cpp delete mode 100644 src/util/ref.h diff --git a/src/Makefile.am b/src/Makefile.am index 9903c2e9b3a..4e09c86ebd7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -243,7 +243,6 @@ BITCOIN_CORE_H = \ util/moneystr.h \ util/rbf.h \ util/readwritefile.h \ - util/ref.h \ util/settings.h \ util/sock.h \ util/spanparsing.h \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index e00f17a83fc..ef03f635795 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -110,7 +110,6 @@ BITCOIN_TESTS =\ test/prevector_tests.cpp \ test/raii_event_tests.cpp \ test/random_tests.cpp \ - test/ref_tests.cpp \ test/reverselock_tests.cpp \ test/rpc_tests.cpp \ test/sanity_tests.cpp \ diff --git a/src/test/ref_tests.cpp b/src/test/ref_tests.cpp deleted file mode 100644 index 0ec0799fbcb..00000000000 --- a/src/test/ref_tests.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2020 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include - -#include - -BOOST_AUTO_TEST_SUITE(ref_tests) - -BOOST_AUTO_TEST_CASE(ref_test) -{ - util::Ref ref; - BOOST_CHECK(!ref.Has()); - BOOST_CHECK_THROW(ref.Get(), NonFatalCheckError); - int value = 5; - ref.Set(value); - BOOST_CHECK(ref.Has()); - BOOST_CHECK_EQUAL(ref.Get(), 5); - ++ref.Get(); - BOOST_CHECK_EQUAL(ref.Get(), 6); - BOOST_CHECK_EQUAL(value, 6); - ++value; - BOOST_CHECK_EQUAL(value, 7); - BOOST_CHECK_EQUAL(ref.Get(), 7); - BOOST_CHECK(!ref.Has()); - BOOST_CHECK_THROW(ref.Get(), NonFatalCheckError); - ref.Clear(); - BOOST_CHECK(!ref.Has()); - BOOST_CHECK_THROW(ref.Get(), NonFatalCheckError); -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/util/ref.h b/src/util/ref.h deleted file mode 100644 index 9685ea9fec0..00000000000 --- a/src/util/ref.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2020 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_UTIL_REF_H -#define BITCOIN_UTIL_REF_H - -#include - -#include - -namespace util { - -/** - * Type-safe dynamic reference. - * - * This implements a small subset of the functionality in C++17's std::any - * class, and can be dropped when the project updates to C++17 - * (https://github.com/bitcoin/bitcoin/issues/16684) - */ -class Ref -{ -public: - Ref() = default; - template Ref(T& value) { Set(value); } - template T& Get() const { CHECK_NONFATAL(Has()); return *static_cast(m_value); } - template void Set(T& value) { m_value = &value; m_type = std::type_index(typeid(T)); } - template bool Has() const { return m_value && m_type == std::type_index(typeid(T)); } - void Clear() { m_value = nullptr; m_type = std::type_index(typeid(void)); } - -private: - void* m_value = nullptr; - std::type_index m_type = std::type_index(typeid(void)); -}; - -} // namespace util - -#endif // BITCOIN_UTIL_REF_H diff --git a/test/lint/extended-lint-cppcheck.sh b/test/lint/extended-lint-cppcheck.sh index b2ed811cdab..0ab6aad50ce 100755 --- a/test/lint/extended-lint-cppcheck.sh +++ b/test/lint/extended-lint-cppcheck.sh @@ -57,7 +57,6 @@ IGNORED_WARNINGS=( "src/test/checkqueue_tests.cpp:.* Struct 'UniqueCheck' has a constructor with 1 argument that is not explicit." "src/test/fuzz/util.h:.* Class 'FuzzedFileProvider' has a constructor with 1 argument that is not explicit." "src/test/fuzz/util.h:.* Class 'FuzzedAutoFileProvider' has a constructor with 1 argument that is not explicit." - "src/util/ref.h:.* Class 'Ref' has a constructor with 1 argument that is not explicit." "src/wallet/db.h:.* Class 'BerkeleyEnvironment' has a constructor with 1 argument that is not explicit." )