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>.
Loading...
Searching...
No Matches
qassert.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qassert.h"
5
6#include <QtCore/qlogging.h>
7
8#include <cstdlib>
9#include <cstdio>
10#include <exception>
11#ifndef QT_NO_EXCEPTIONS
12#include <new>
13#endif
14
15#if defined(Q_CC_MSVC)
16# include <crtdbg.h>
17#endif
18#ifdef Q_OS_WIN
19# include <qt_windows.h>
20#endif
21
23
24void qAbort()
25{
26#ifdef Q_OS_WIN
27 // std::abort() in the MSVC runtime will call _exit(3) if the abort
28 // behavior is _WRITE_ABORT_MSG - see also _set_abort_behavior(). This is
29 // the default for a debug-mode build of the runtime. Worse, MinGW's
30 // std::abort() implementation (in msvcrt.dll) is basically a call to
31 // _exit(3) too. Unfortunately, _exit() and _Exit() *do* run the static
32 // destructors of objects in DLLs, a violation of the C++ standard (see
33 // [support.start.term]). So we bypass std::abort() and directly
34 // terminate the application.
35
36# if defined(Q_CC_MSVC)
37 if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
38 __fastfail(FAST_FAIL_FATAL_APP_EXIT);
39# else
40 RaiseFailFastException(nullptr, nullptr, 0);
41# endif
42
43 // Fallback
44 TerminateProcess(GetCurrentProcess(), STATUS_FATAL_APP_EXIT);
45
46 // Tell the compiler the application has stopped.
48#else // !Q_OS_WIN
49 std::abort();
50#endif
51}
52
99/*
100 The Q_ASSERT macro calls this function when the test fails.
101*/
102void qt_assert(const char *assertion, const char *file, int line) noexcept
103{
104 QMessageLogger(file, line, nullptr)
105 .fatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
106}
107
108/*
109 The Q_ASSERT_X macro calls this function when the test fails.
110*/
111void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept
112{
113 QMessageLogger(file, line, nullptr)
114 .fatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
115}
116
152void qt_check_pointer(const char *n, int l) noexcept
153{
154 // make separate printing calls so that the first one may flush;
155 // the second one could want to allocate memory (fputs prints a
156 // newline and stderr auto-flushes).
157 fputs("Out of memory", stderr);
158 fprintf(stderr, " in %s, line %d\n", n, l);
159
160 std::terminate();
161}
162
163/*
164 \internal
165 Allows you to throw an exception without including <new>
166 Called internally from Q_CHECK_PTR on certain OS combinations
167*/
169{
170#ifndef QT_NO_EXCEPTIONS
171 throw std::bad_alloc();
172#else
173 std::terminate();
174#endif
175}
176
\inmodule QtCore
Definition qlogging.h:72
void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void fatal(const char *msg,...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(2
Logs a fatal message specified with format msg.
Definition qlogging.cpp:875
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE void qAbort()
Definition qassert.cpp:24
void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept
Definition qassert.cpp:111
void qt_check_pointer(const char *n, int l) noexcept
Definition qassert.cpp:152
void qBadAlloc()
Definition qassert.cpp:168
#define Q_UNREACHABLE_IMPL()
GLfloat n
QFile file
[0]