Skip to content

Commit fa4ceba

Browse files
author
MarcoFalke
committed
util: Make Assume() usable as unary expression
1 parent d099894 commit fa4ceba

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/test/util_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ BOOST_AUTO_TEST_CASE(util_check)
7676
const int two = *Assert(p_two);
7777
Assert(two == 2);
7878
Assert(true);
79+
// Check that Assume can be used as unary expression
80+
const bool result{Assume(two == 2)};
81+
Assert(result);
7982
}
8083

8184
BOOST_AUTO_TEST_CASE(util_criticalsection)

src/util/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ T get_pure_r_value(T&& val)
6969
#ifdef ABORT_ON_FAILED_ASSUME
7070
#define Assume(val) Assert(val)
7171
#else
72-
#define Assume(val) ((void)(val))
72+
#define Assume(val) ([&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); return std::forward<decltype(get_pure_r_value(val))>(check); }())
7373
#endif
7474

7575
#endif // BITCOIN_UTIL_CHECK_H

0 commit comments

Comments
 (0)