Commit a99615fe authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

support FOLLY_SAFE_CHECK with no message args

Summary:
Permit calls of the form:

```lang=c++
FOLLY_SAFE_DCHECK(expr);
```

Reviewed By: ot

Differential Revision: D27843903

fbshipit-source-id: 23869720822fcdba0845c42279855b101c8e2b36
parent dbfa7c45
...@@ -31,24 +31,25 @@ ...@@ -31,24 +31,25 @@
#define FOLLY_DETAIL_SAFE_CHECK_LINKAGE static #define FOLLY_DETAIL_SAFE_CHECK_LINKAGE static
#endif #endif
#define FOLLY_DETAIL_SAFE_CHECK_IMPL(d, p, expr, expr_s, ...) \ #define FOLLY_DETAIL_SAFE_CHECK_IMPL(d, p, expr, expr_s, ...) \
do { \ do { \
if ((!d || ::folly::kIsDebug || ::folly::kIsSanitize) && \ if ((!d || ::folly::kIsDebug || ::folly::kIsSanitize) && \
!static_cast<bool>(expr)) { \ !static_cast<bool>(expr)) { \
FOLLY_DETAIL_SAFE_CHECK_LINKAGE constexpr auto \ FOLLY_DETAIL_SAFE_CHECK_LINKAGE constexpr auto \
__folly_detail_safe_assert_fun = __func__; \ __folly_detail_safe_assert_fun = __func__; \
FOLLY_DETAIL_SAFE_CHECK_LINKAGE constexpr ::folly::detail:: \ FOLLY_DETAIL_SAFE_CHECK_LINKAGE constexpr ::folly::detail:: \
safe_assert_arg __folly_detail_safe_assert_arg{ \ safe_assert_arg __folly_detail_safe_assert_arg{ \
FOLLY_PP_STRINGIZE(expr_s), \ FOLLY_PP_STRINGIZE(expr_s), \
__FILE__, \ __FILE__, \
__LINE__, \ __LINE__, \
__folly_detail_safe_assert_fun, \ __folly_detail_safe_assert_fun, \
::folly::detail::safe_assert_msg_types<decltype( \ ::folly::detail::safe_assert_msg_types<decltype( \
::folly::detail::safe_assert_msg_types_seq_of( \ ::folly::detail::safe_assert_msg_types_seq_of( \
__VA_ARGS__))>::value.data}; \ __VA_ARGS__))>::value.data}; \
::folly::detail::safe_assert_terminate<p>( \ ::folly::detail::safe_assert_terminate<p>( \
__folly_detail_safe_assert_arg, __VA_ARGS__); \ __folly_detail_safe_assert_arg FOLLY_PP_DETAIL_APPEND_VA_ARG( \
} \ __VA_ARGS__)); \
} \
} while (false) } while (false)
// FOLLY_SAFE_CHECK // FOLLY_SAFE_CHECK
......
...@@ -49,6 +49,16 @@ TEST(SafeAssert, AssertionFailure) { ...@@ -49,6 +49,16 @@ TEST(SafeAssert, AssertionFailure) {
EXPECT_DEATH(fail(), "Message: hello"); EXPECT_DEATH(fail(), "Message: hello");
} }
TEST(SafeAssert, AssertionFailureVariadicFormattedArgs) {
FOLLY_SAFE_CHECK(true);
EXPECT_DEATH( //
([] { FOLLY_SAFE_CHECK(false); }()), //
"Assertion failure: false");
EXPECT_DEATH( //
([] { FOLLY_SAFE_CHECK(false, 17ull, " < ", 18ull); }()), //
"Message: 17 < 18");
}
TEST(SafeAssert, AssertionFailureErrno) { TEST(SafeAssert, AssertionFailureErrno) {
EXPECT_DEATH( EXPECT_DEATH(
([] { FOLLY_SAFE_PCHECK((errno = EINVAL) && false, "hello"); }()), ([] { FOLLY_SAFE_PCHECK((errno = EINVAL) && false, "hello"); }()),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment