Skip to content

Commit fa53635

Browse files
author
MarcoFalke
committed
util: Make Assert work with any value
1 parent 5f96bce commit fa53635

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/test/util_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ namespace BCLog {
4141

4242
BOOST_FIXTURE_TEST_SUITE(util_tests, BasicTestingSetup)
4343

44+
BOOST_AUTO_TEST_CASE(util_check)
45+
{
46+
// Check that Assert can forward
47+
const std::unique_ptr<int> p_two = Assert(MakeUnique<int>(2));
48+
// Check that Assert works on lvalues and rvalues
49+
const int two = *Assert(p_two);
50+
Assert(two == 2);
51+
Assert(true);
52+
}
53+
4454
BOOST_AUTO_TEST_CASE(util_criticalsection)
4555
{
4656
RecursiveMutex cs;

src/util/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ T get_pure_r_value(T&& val)
5454
}
5555

5656
/** Identity function. Abort if the value compares equal to zero */
57-
#define Assert(val) [&]() -> decltype(get_pure_r_value(val))& { auto& check = (val); assert(#val && check); return check; }()
57+
#define Assert(val) [&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); assert(#val && check); return std::forward<decltype(get_pure_r_value(val))>(check); }()
5858

5959
#endif // BITCOIN_UTIL_CHECK_H

0 commit comments

Comments
 (0)