diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 6456438da1f..fac7680b196 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -47,6 +47,7 @@ qt_internal_add_module(Core # Keep the rest alphabetical compat/removed_api.cpp global/archdetect.cpp + global/qassert.cpp global/qassert.h global/qcompare_impl.h global/qcompare.h global/qcompilerdetection.h diff --git a/src/corelib/global/qassert.cpp b/src/corelib/global/qassert.cpp new file mode 100644 index 00000000000..9b7e5d9a387 --- /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 + +QT_BEGIN_NAMESPACE + +/*! + \macro void Q_ASSERT(bool test) + \relates + + 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 + + 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 diff --git a/src/corelib/global/qassert.h b/src/corelib/global/qassert.h new file mode 100644 index 00000000000..acc311814bb --- /dev/null +++ b/src/corelib/global/qassert.h @@ -0,0 +1,48 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QASSERT_H +#define QASSERT_H + +#include +#include + +#if 0 +#pragma qt_class(QtAssert) +#pragma qt_sync_stop_processing +#endif + +QT_BEGIN_NAMESPACE + +#ifndef Q_CC_MSVC +Q_NORETURN +#endif +Q_DECL_COLD_FUNCTION +Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) noexcept; + +#if !defined(Q_ASSERT) +# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) +# define Q_ASSERT(cond) static_cast(false && (cond)) +# else +# define Q_ASSERT(cond) ((cond) ? static_cast(0) : qt_assert(#cond, __FILE__, __LINE__)) +# endif +#endif + +#ifndef Q_CC_MSVC +Q_NORETURN +#endif +Q_DECL_COLD_FUNCTION +Q_CORE_EXPORT +void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept; + +#if !defined(Q_ASSERT_X) +# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) +# define Q_ASSERT_X(cond, where, what) static_cast(false && (cond)) +# else +# define Q_ASSERT_X(cond, where, what) ((cond) ? static_cast(0) : qt_assert_x(where, what, __FILE__, __LINE__)) +# endif +#endif + +QT_END_NAMESPACE + +#endif // QASSERT_H diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 075a9b6926f..c8c55c1a38a 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2960,52 +2960,6 @@ QByteArray QSysInfo::bootUniqueId() return QByteArray(); }; -/*! - \macro void Q_ASSERT(bool test) - \relates - - 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 - - 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} -*/ - /*! \macro void Q_ASSUME(bool expr) \relates @@ -3170,23 +3124,6 @@ Q_NORETURN void qTerminate() noexcept std::terminate(); } -/* - 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); -} - - /* Dijkstra's bisection algorithm to find the square root of an integer. Deliberately not exported as part of the Qt API, but used in both diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 9d482e71073..93954a4826c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -633,33 +633,9 @@ Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() noexcept; # define QT_DEBUG #endif -#ifndef Q_CC_MSVC -Q_NORETURN -#endif -Q_DECL_COLD_FUNCTION -Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) noexcept; - -#if !defined(Q_ASSERT) -# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) -# define Q_ASSERT(cond) static_cast(false && (cond)) -# else -# define Q_ASSERT(cond) ((cond) ? static_cast(0) : qt_assert(#cond, __FILE__, __LINE__)) -# endif -#endif - -#ifndef Q_CC_MSVC -Q_NORETURN -#endif -Q_DECL_COLD_FUNCTION -Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept; - -#if !defined(Q_ASSERT_X) -# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) -# define Q_ASSERT_X(cond, where, what) static_cast(false && (cond)) -# else -# define Q_ASSERT_X(cond, where, what) ((cond) ? static_cast(0) : qt_assert_x(where, what, __FILE__, __LINE__)) -# endif -#endif +QT_BEGIN_INCLUDE_NAMESPACE +#include +QT_END_INCLUDE_NAMESPACE Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) noexcept; Q_NORETURN Q_DECL_COLD_FUNCTION diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt index df572f9e8db..cac8689be31 100644 --- a/src/tools/bootstrap/CMakeLists.txt +++ b/src/tools/bootstrap/CMakeLists.txt @@ -14,6 +14,7 @@ qt_add_library(Bootstrap STATIC) # special case end qt_internal_extend_target(Bootstrap SOURCES + ../../corelib/global/qassert.cpp ../../corelib/global/qendian.cpp ../../corelib/global/qenvironmentvariables.cpp ../../corelib/global/qfloat16.cpp