summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qassert.cpp
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-08-01 15:09:42 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2022-08-05 15:54:06 +0200
commitb3fd4b8adf929923b33295fa03783bcdbebe442f (patch)
tree63943fa4dd8af87ae2fc5cbabb43c8042c4ad6e6 /src/corelib/global/qassert.cpp
parentf9c73e540a0a4a7dcd7dbf0a172b119f16ed7e5f (diff)
Extract header qassert.h from qglobal.h
For now qassert.h is included in the middle of qglobal.h, since some of the code below needs it, but this will be cleaned up when that code is moved in its own header. Task-number: QTBUG-99313 Change-Id: I2cdfed44f5c8772c1dad4797cf8edc6cb4c964b4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/global/qassert.cpp')
-rw-r--r--src/corelib/global/qassert.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/corelib/global/qassert.cpp b/src/corelib/global/qassert.cpp
new file mode 100644
index 0000000000..9b7e5d9a38
--- /dev/null
+++ b/src/corelib/global/qassert.cpp
@@ -0,0 +1,74 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+#include "qassert.h"
+
+#include <QtCore/qlogging.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \macro void Q_ASSERT(bool test)
+ \relates <QtAssert>
+
+ Prints a warning message containing the source code file name and
+ line number if \a test is \c false.
+
+ Q_ASSERT() is useful for testing pre- and post-conditions
+ during development. It does nothing if \c QT_NO_DEBUG was defined
+ during compilation.
+
+ Example:
+
+ \snippet code/src_corelib_global_qglobal.cpp 17
+
+ If \c b is zero, the Q_ASSERT statement will output the following
+ message using the qFatal() function:
+
+ \snippet code/src_corelib_global_qglobal.cpp 18
+
+ \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
+*/
+
+/*!
+ \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
+ \relates <QtAssert>
+
+ Prints the message \a what together with the location \a where,
+ the source file name and line number if \a test is \c false.
+
+ Q_ASSERT_X is useful for testing pre- and post-conditions during
+ development. It does nothing if \c QT_NO_DEBUG was defined during
+ compilation.
+
+ Example:
+
+ \snippet code/src_corelib_global_qglobal.cpp 19
+
+ If \c b is zero, the Q_ASSERT_X statement will output the following
+ message using the qFatal() function:
+
+ \snippet code/src_corelib_global_qglobal.cpp 20
+
+ \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
+*/
+
+/*
+ The Q_ASSERT macro calls this function when the test fails.
+*/
+void qt_assert(const char *assertion, const char *file, int line) noexcept
+{
+ QMessageLogger(file, line, nullptr)
+ .fatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
+}
+
+/*
+ The Q_ASSERT_X macro calls this function when the test fails.
+*/
+void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept
+{
+ QMessageLogger(file, line, nullptr)
+ .fatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
+}
+
+QT_END_NAMESPACE