Skip to content

Commit 4e01f19

Browse files
authored
Merge pull request #224 from philipwjones/omega/assert-fix
fixes behavior of OMEGA_ASSERT and OMEGA_REQUIRE
2 parents d6b5d9f + ab56e94 commit 4e01f19

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

components/omega/doc/devGuide/Error.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ macros:
3131
OMEGA_ASSERT(Condition, Message, addition args for message);
3232
OMEGA_REQUIRE(Condition, Message, addition args for message);
3333
```
34-
These emulate the behavior of the C++ assert function. The `ASSERT` macro
35-
is only evaluated in debug builds while the `REQUIRE` macro is always
36-
evaluated. These have identical behavior to the critical error macro, but
37-
take the additional boolean argument of the condition to be checked.
34+
These emulate the behavior of the C++ assert function in which the condition
35+
is checked and a critical error is thrown if the condition is not met (false).
36+
The `ASSERT` macro is only evaluated in debug builds while the `REQUIRE`
37+
macro is always evaluated. These have identical behavior to the critical error
38+
macro, but take the additional boolean argument of the condition to be checked.
3839
3940
The remaining macros operate on or with an Error class that contains an error
4041
code and an error message. These can be used as a return code, as in:

components/omega/src/infra/Error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Error::Error(ErrorCode ErrCode, // [in] error code to assign
213213
/// It is only active for debug builds.
214214
#ifdef OMEGA_DEBUG
215215
#define OMEGA_ASSERT(_Condition, _ErrMsg, ...) \
216-
if (_Condition) { \
216+
if (!_Condition) { \
217217
LOG_CRITICAL(_ErrMsg, ##__VA_ARGS__); \
218218
cpptrace::generate_trace().print(); \
219219
OMEGA::Error::abort(); \
@@ -225,7 +225,7 @@ Error::Error(ErrorCode ErrCode, // [in] error code to assign
225225
/// This macro checks for a required condition and exits if not met
226226
/// It is always evaluated (unlike ASSERT for debug builds)
227227
#define OMEGA_REQUIRE(_Condition, _ErrMsg, ...) \
228-
if (_Condition) { \
228+
if (!_Condition) { \
229229
LOG_CRITICAL(_ErrMsg, ##__VA_ARGS__); \
230230
cpptrace::generate_trace().print(); \
231231
OMEGA::Error::abort(); \

components/omega/test/infra/ErrorTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ void passError2(Error &Err) {
5959
// Alternative critical failure tests
6060
// CHECK_ERROR_ABORT(Err, "Expected critical error with args: {} {} {}",
6161
// MsgArgStr, MsgArgInt, MsgArgReal);
62-
// OMEGA_REQUIRE(!Err.isSuccess(),
62+
// OMEGA_REQUIRE(Err.isSuccess(),
6363
// "Expected Error with args: {} {} {}", MsgArgStr, MsgArgInt,
6464
// MsgArgReal);
6565
// This one requires a debug build
66-
// OMEGA_ASSERT(!Err.isSuccess(),
66+
// OMEGA_ASSERT(Err.isSuccess(),
6767
// "Expected Error with args: {} {} {}", MsgArgStr, MsgArgInt,
6868
// MsgArgReal);
6969
}

0 commit comments

Comments
 (0)