Extract header qexceptionhandling.h from qglobal.h

As a drive-by, remove the unused include for std::bad_alloc from
qglobal.cpp.

Task-number: QTBUG-99313
Change-Id: I4b26b4413e6fe7ac3b1e285d0db5b81b429a4713
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
bb10
Sona Kurazyan 2022-08-16 17:18:13 +02:00
parent 7d22847371
commit 0329792602
5 changed files with 67 additions and 41 deletions

View File

@ -54,6 +54,7 @@ qt_internal_add_module(Core
global/qcontainerinfo.h
global/qendian.cpp global/qendian.h global/qendian_p.h
global/qenvironmentvariables.cpp global/qenvironmentvariables.h
global/qexceptionhandling.cpp global/qexceptionhandling.h
global/qflags.h
global/qfloat16.cpp global/qfloat16.h
global/qforeach.h

View File

@ -0,0 +1,20 @@
// 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
#include "qexceptionhandling.h"
#include <exception>
QT_BEGIN_NAMESPACE
/*
\internal
Allows you to call std::terminate() without including <exception>.
Called internally from QT_TERMINATE_ON_EXCEPTION
*/
Q_NORETURN void qTerminate() noexcept
{
std::terminate();
}
QT_END_NAMESPACE

View File

@ -0,0 +1,45 @@
// 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 QEXCEPTIONHANDLING_H
#define QEXCEPTIONHANDLING_H
#include <QtCore/qtconfigmacros.h>
#include <QtCore/qcompilerdetection.h>
#if 0
#pragma qt_class(QtExceptionHandling)
#pragma qt_sync_stop_processing
#endif
QT_BEGIN_NAMESPACE
/* These wrap try/catch so we can switch off exceptions later.
Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
the exception instance in the catch block.
If you can't live with those constraints, don't use these macros.
Use the QT_NO_EXCEPTIONS macro to protect your code instead.
*/
Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept;
#ifdef QT_NO_EXCEPTIONS
# define QT_TRY if (true)
# define QT_CATCH(A) else
# define QT_THROW(A) qt_noop()
# define QT_RETHROW qt_noop()
# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
#else
# define QT_TRY try
# define QT_CATCH(A) catch (A)
# define QT_THROW(A) throw A
# define QT_RETHROW throw
# ifdef Q_COMPILER_NOEXCEPT
# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
# else
# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false)
# endif
#endif
QT_END_NAMESPACE
#endif // QEXCEPTIONHANDLING_H

View File

@ -22,11 +22,6 @@
#include <stdarg.h>
#include <string.h>
#include <exception> // For std::terminate
#ifndef QT_NO_EXCEPTIONS
#include <new> // For std::bad_alloc
#endif
#include <errno.h>
#if defined(Q_CC_MSVC)
# include <crtdbg.h>
@ -2640,16 +2635,6 @@ QByteArray QSysInfo::bootUniqueId()
If this macro is used outside a function, the behavior is undefined.
*/
/*
\internal
Allows you to call std::terminate() without including <exception>.
Called internally from QT_TERMINATE_ON_EXCEPTION
*/
Q_NORETURN void qTerminate() noexcept
{
std::terminate();
}
/*
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

View File

@ -225,32 +225,6 @@ private:
#endif // Q_OS_DARWIN
/* These wrap try/catch so we can switch off exceptions later.
Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
the exception instance in the catch block.
If you can't live with those constraints, don't use these macros.
Use the QT_NO_EXCEPTIONS macro to protect your code instead.
*/
Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept;
#ifdef QT_NO_EXCEPTIONS
# define QT_TRY if (true)
# define QT_CATCH(A) else
# define QT_THROW(A) qt_noop()
# define QT_RETHROW qt_noop()
# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
#else
# define QT_TRY try
# define QT_CATCH(A) catch (A)
# define QT_THROW(A) throw A
# define QT_RETHROW throw
# ifdef Q_COMPILER_NOEXCEPT
# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
# else
# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false)
# endif
#endif
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() noexcept;
/*
@ -407,6 +381,7 @@ QT_END_NAMESPACE
#include <QtCore/qatomic.h>
#include <QtCore/qenvironmentvariables.h>
#include <QtCore/qexceptionhandling.h>
#include <QtCore/qforeach.h>
#include <QtCore/qglobalstatic.h>
#include <QtCore/qminmax.h>