Commit e780e3ed authored by Harris Hancock's avatar Harris Hancock

Use IIFE instead of GNU statement expression

An immediately-invoked function expression with a default reference
capture list should be roughly equivalent to a GNU compound statement
expression. I'm unsure whether or not the result should be returned by
kj::mv() -- I would expect the compiler to optimize appropriately, but
have not tested this.

Note: There are two versions of KJ_REQUIRE_NONNULL in kj/debug.h: one that
works with MSVC's preprocessor, and one which works with the standard-
compliant preprocessor. This commit only touches the MSVC version of the
macro, because that is the minimum necessary work to get it to compile in
MSVC. However, it may make sense to convert the other one to use IIFE as
well.
parent 1b677077
......@@ -178,14 +178,14 @@ namespace kj {
KJ_UNIQUE_NAME(_kjContext)(KJ_UNIQUE_NAME(_kjContextFunc))
#define KJ_REQUIRE_NONNULL(value, ...) \
(*({ \
(*[&] { \
auto _kj_result = ::kj::_::readMaybe(value); \
if (KJ_UNLIKELY(!_kj_result)) { \
::kj::_::Debug::Fault(__FILE__, __LINE__, ::kj::Exception::Type::FAILED, \
#value " != nullptr", "" #__VA_ARGS__, __VA_ARGS__).fatal(); \
} \
kj::mv(_kj_result); \
}))
return _kj_result; \
}())
#define KJ_EXCEPTION(type, ...) \
::kj::Exception(::kj::Exception::Type::type, __FILE__, __LINE__, \
......
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