From fa4cebadcffd9112da4b13c7cc7ccf21e2bee887 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 28 Feb 2021 16:38:19 +0100 Subject: [PATCH] util: Make Assume() usable as unary expression --- src/test/util_tests.cpp | 3 +++ src/util/check.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 5a46002a79..32db6d6c83 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -76,6 +76,9 @@ BOOST_AUTO_TEST_CASE(util_check) const int two = *Assert(p_two); Assert(two == 2); Assert(true); + // Check that Assume can be used as unary expression + const bool result{Assume(two == 2)}; + Assert(result); } BOOST_AUTO_TEST_CASE(util_criticalsection) diff --git a/src/util/check.h b/src/util/check.h index bc62da3440..e60088a2c6 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -69,7 +69,7 @@ T get_pure_r_value(T&& val) #ifdef ABORT_ON_FAILED_ASSUME #define Assume(val) Assert(val) #else -#define Assume(val) ((void)(val)) +#define Assume(val) ([&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); return std::forward(check); }()) #endif #endif // BITCOIN_UTIL_CHECK_H