diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-03-22 08:35:18 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-03-22 08:35:21 +0100 |
commit | 1e4a3c057a9bf8d64aa414d783dc9aa37bd67536 (patch) | |
tree | 013a46caf0fc6ab4cc5af1ae87aec700f04d9e35 | |
parent | 786654aa5e0b7a7f91404e8fb9c3b2a7f7a421ba (diff) | |
parent | fa4cebadcffd9112da4b13c7cc7ccf21e2bee887 (diff) |
Merge #21317: util: Make Assume() usable as unary expression
fa4cebadcffd9112da4b13c7cc7ccf21e2bee887 util: Make Assume() usable as unary expression (MarcoFalke)
Pull request description:
Assume shouldn't behave different at the call site depending on build flags. Currently compilation fails if it is used as expression. Fix that by using the lambda approach from `Assert()` without the `assert()`.
ACKs for top commit:
jnewbery:
ACK fa4cebadcffd9112da4b13c7cc7ccf21e2bee887
practicalswift:
cr ACK fa4cebadcffd9112da4b13c7cc7ccf21e2bee887: patch looks correct and commit hash starts with `fa`
Tree-SHA512: 9ec9ac8d410cdaf5e4e28df571a89e3d23d38e05a7027bb726cae3da6e9314734277e5a218e9e090cc17e10db763da71052c229ad642077ca5824ee42022f3ed
-rw-r--r-- | src/test/util_tests.cpp | 3 | ||||
-rw-r--r-- | src/util/check.h | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 2e7685bf9e..5ac09b05db 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -77,6 +77,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<decltype(get_pure_r_value(val))>(check); }()) #endif #endif // BITCOIN_UTIL_CHECK_H |