aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-02-28 16:38:19 +0100
committerMarcoFalke <falke.marco@gmail.com>2021-03-04 12:03:50 +0100
commitfa4cebadcffd9112da4b13c7cc7ccf21e2bee887 (patch)
tree934dc4c244fd2d7747feb2b751ebdb1f52c52968 /src
parentd099894ec124598b37bd4a0a41b2c93e0034108f (diff)
util: Make Assume() usable as unary expression
Diffstat (limited to 'src')
-rw-r--r--src/test/util_tests.cpp3
-rw-r--r--src/util/check.h2
2 files changed, 4 insertions, 1 deletions
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<decltype(get_pure_r_value(val))>(check); }())
#endif
#endif // BITCOIN_UTIL_CHECK_H