Use BOOST_PP_OVERLOAD() to allow invoking the assertion macros without a message

This commit is contained in:
Kamil Śliwak
2021-10-04 12:05:00 +02:00
committed by chriseth
parent 4fe6aa1328
commit 0745842d46
3 changed files with 101 additions and 10 deletions
+21 -2
View File
@@ -21,12 +21,31 @@
#include <libsolutil/Assertions.h>
#include <libsolutil/Exceptions.h>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/facilities/overload.hpp>
namespace solidity::smtutil
{
struct SMTLogicError: virtual util::Exception {};
#define smtAssert(CONDITION, DESCRIPTION) \
assertThrowWithDefaultDescription(CONDITION, SMTLogicError, DESCRIPTION, "SMT assertion failed")
/// Assertion that throws an SMTLogicError containing the given description if it is not met.
#if !BOOST_PP_VARIADICS_MSVC
#define smtAssert(...) BOOST_PP_OVERLOAD(smtAssert_,__VA_ARGS__)(__VA_ARGS__)
#else
#define smtAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(smtAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY())
#endif
#define smtAssert_1(CONDITION) \
smtAssert_2(CONDITION, "")
#define smtAssert_2(CONDITION, DESCRIPTION) \
assertThrowWithDefaultDescription( \
CONDITION, \
::solidity::smtutil::SMTLogicError, \
DESCRIPTION, \
"SMT assertion failed" \
)
}