Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
#include "qssgassert_p.h"
Go to the source code of this file.
Functions | |
QT_BEGIN_NAMESPACE void | qssgWriteAssertLocation (const char *msg) |
Collection of assert checks that causes a soft or hard assert depending on the build. | |
QT_BEGIN_NAMESPACE void qssgWriteAssertLocation | ( | const char * | msg | ) |
Collection of assert checks that causes a soft or hard assert depending on the build.
Unlike Q_ASSERT(), which is a no-op for non-debug build, QSSG_ASSERT() etc., will print a warning in non-developer builds (soft assert) or terminate on developer-build (hard assert).
\macro QSSG_ASSERT(condition, action)
The assert will be fatal in developer builds if condition is not met. In non-developer builds the assert is "soft" and will instead print a warning with the reason and location of the assert before execution action. The action can be for example be: return
, break
or continue
.
For example, writing:
\badcode QSSG_ASSERT(ptr != nullptr, return);
other actions are of course possible, e.g., in a loop it might be better to do:
\badcode QSSG_ASSERT(ptr != nullptr, continue);
is the equivalent to:
\badcode Q_ASSERT(ptr != nullptr); if (ptr != nullptr) { qWarning() << "Something unexpected here, proceeding will be fatal!"; return; }
\macro QSSG_ASSERT_X(condition, message, action)
Same as \l QSSG_ASSERT() but with a custom message that will be print if condition is not met.
\macro QSSG_CHECK(condition)
Similar to \l QSSG_ASSERT but without an action. Convenient when the condition is expected to be valid, but it's not immediately fatal if the current code path continues.
\badcode QSSG_CHECK(ptr != nullptr);
is the equivalent to:
\badcode Q_ASSERT(ptr != nullptr); if (ptr != nullptr) qWarning() << "Something unexpected here, will probably not work as expected!";
\macro QSSG_CHECK_X(condition, message)
Same as \l QSSG_CHECK() but with a custom message that will be print if condition is not met.
\macro QSSG_GUARD(condition)
Check that returns the result of condition. As with the other assert functions, a call to QSSG_GUARD, when condition is not met, is fatal for developer builds.
\badcode
if (QSSG_GUARD(ptr != nullptr)) { ... // OK } else { ... // We shouldn't be here! }
is the equivalent to:
\badcode if (ptr != nullptr) { ... // OK } else { Q_ASSERT(ptr != nullptr); qWarning() << "Something unexpected here!"; }
\macro QSSG_GUARD_X(condition, message)
Same as \l QSSG_GUARD() but with a custom message that will be print if condition is not met.
\macro QSSG_DEBUG_COND(condition)
Macro for condition that should only be run in debug builds. In releases build the macro produces an "almost-no-op" condition (always true) and the condition is never run. Can e.g., be combined with the assert checks to add potentially expensive sanity checks that should only be run in debug builds.
\badcode QSSG_CEHCK(QSSG_DEBUG_COND(!list.contains(...)));
In a release build the QSSG_DEBUG_COND
will never return false
and the condition will never be evaluated.
Definition at line 140 of file qssgassert.cpp.