mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
refactor: Add LIFETIMEBOUND / -Wdangling-gsl to Assert()
This commit is contained in:
parent
816ca01650
commit
fa3ea81c3e
2 changed files with 8 additions and 2 deletions
|
@ -122,6 +122,11 @@ BOOST_AUTO_TEST_CASE(util_check)
|
||||||
|
|
||||||
// Check nested Asserts
|
// Check nested Asserts
|
||||||
BOOST_CHECK_EQUAL(Assert((Assert(x).test() ? 3 : 0)), 3);
|
BOOST_CHECK_EQUAL(Assert((Assert(x).test() ? 3 : 0)), 3);
|
||||||
|
|
||||||
|
// Check -Wdangling-gsl does not trigger when copying the int. (It would
|
||||||
|
// trigger on "const int&")
|
||||||
|
const int nine{*Assert(std::optional<int>{9})};
|
||||||
|
BOOST_CHECK_EQUAL(9, nine);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_criticalsection)
|
BOOST_AUTO_TEST_CASE(util_criticalsection)
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <config/bitcoin-config.h>
|
#include <config/bitcoin-config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -24,7 +25,7 @@ class NonFatalCheckError : public std::runtime_error
|
||||||
|
|
||||||
/** Helper for CHECK_NONFATAL() */
|
/** Helper for CHECK_NONFATAL() */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T&& inline_check_non_fatal(T&& val, const char* file, int line, const char* func, const char* assertion)
|
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)
|
||||||
{
|
{
|
||||||
if (!(val)) {
|
if (!(val)) {
|
||||||
throw NonFatalCheckError(
|
throw NonFatalCheckError(
|
||||||
|
@ -56,7 +57,7 @@ void assertion_fail(const char* file, int line, const char* func, const char* as
|
||||||
|
|
||||||
/** Helper for Assert()/Assume() */
|
/** Helper for Assert()/Assume() */
|
||||||
template <bool IS_ASSERT, typename T>
|
template <bool IS_ASSERT, typename T>
|
||||||
T&& inline_assertion_check(T&& val, [[maybe_unused]] const char* file, [[maybe_unused]] int line, [[maybe_unused]] const char* func, [[maybe_unused]] const char* assertion)
|
T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* file, [[maybe_unused]] int line, [[maybe_unused]] const char* func, [[maybe_unused]] const char* assertion)
|
||||||
{
|
{
|
||||||
if constexpr (IS_ASSERT
|
if constexpr (IS_ASSERT
|
||||||
#ifdef ABORT_ON_FAILED_ASSUME
|
#ifdef ABORT_ON_FAILED_ASSUME
|
||||||
|
|
Loading…
Add table
Reference in a new issue