Skip to content

Commit

Permalink
New OEL_ASSERT
Browse files Browse the repository at this point in the history
  • Loading branch information
OleErikPeistorpet committed May 31, 2024
1 parent 9cf16ea commit 6580141
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Another good way, using `resize_for_overwrite`:

Precondition checks are off by default except for Visual C++ debug builds. (Preconditions are the same as std::vector except a few documented cases.) They can be controlled with a global define such as `-D OEL_MEM_BOUND_DEBUG_LVL=2`. But be careful with compilers other than MSVC, the checks should **not** be combined with compiler optimizations unless you set the `-fno-strict-aliasing` flag.

You can customize what happens when a check is triggered. This is done by defining or changing OEL_ABORT or OEL_ASSERT; see `fwd.h`
You can customize what happens when a check is triggered. This is done by defining or changing OEL_ASSERT; see `fwd.h`

### Visual Studio visualizer

Expand Down
28 changes: 17 additions & 11 deletions fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,30 @@
#endif


#ifndef OEL_ABORT
/** @brief If exceptions are disabled, used anywhere that would normally throw. Also used by OEL_ASSERT
//! Used anywhere that would normally throw if exceptions are off (compiler switch)
/**
* Also used instead of throwing std::bad_alloc if OEL_NEW_HANDLER has been defined to non-zero,
* regardless of exceptions being enabled.
*
* Can be defined to something else, but note that it must never return.
* Moreover, don't expect to catch what it throws, because it's used in noexcept functions through OEL_ASSERT. */
* Feel free to define it to something else, but note that it must never return. */
#ifndef OEL_ABORT
#define OEL_ABORT(message) (std::abort(), (void) message)
#endif


#if OEL_MEM_BOUND_DEBUG_LVL == 0
#undef OEL_ASSERT
#define OEL_ASSERT(cond) ((void) 0)
#undef OEL_ASSERT
#define OEL_ASSERT(cond) void(0)
#elif !defined OEL_ASSERT
/** @brief Used for checking preconditions. Can be defined to your own
*
//! Used for checking preconditions. Can be defined to your own
/**
* Used in noexcept functions, so don't expect to catch anything thrown.
* OEL_ASSERT itself should probably be noexcept for optimal performance. */
#define OEL_ASSERT(cond) \
((cond) or (OEL_ABORT("Failed precond: " #cond), false))
* OEL_ASSERT itself should probably be noexcept to avoid bloat. */
#if defined _MSC_VER
#define OEL_ASSERT(cond) ((cond) or (__debugbreak(), false))
#else
#define OEL_ASSERT(cond) ((cond) or (__builtin_trap(), false))
#endif
#endif


Expand Down

0 comments on commit 6580141

Please sign in to comment.