diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include // For MessageSign(), MessageVerify(), MESSAGE_MAGIC #include #include @@ -45,6 +46,15 @@ BOOST_FIXTURE_TEST_SUITE(util_tests, BasicTestingSetup) +BOOST_AUTO_TEST_CASE(util_check) { + // Check that Assert can forward + const std::unique_ptr p_two = Assert(std::make_unique(2)); + // Check that Assert works on lvalues and rvalues + const int two = *Assert(p_two); + Assert(two == 2); + Assert(true); +} + BOOST_AUTO_TEST_CASE(util_criticalsection) { RecursiveMutex cs; diff --git a/src/util/check.h b/src/util/check.h --- a/src/util/check.h +++ b/src/util/check.h @@ -55,10 +55,10 @@ /** Identity function. Abort if the value compares equal to zero */ #define Assert(val) \ - [&]() -> decltype(get_pure_r_value(val)) & { \ - auto &check = (val); \ + [&]() -> decltype(get_pure_r_value(val)) { \ + auto &&check = (val); \ assert(#val &&check); \ - return check; \ + return std::forward(check); \ }() #endif // BITCOIN_UTIL_CHECK_H