summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2022-08-16 17:18:13 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2022-08-19 09:15:39 +0200
commit0329792602310577fa66c6991b891140b6edd210 (patch)
treeef71e52870bc650cff4957057f455635e3c121df
parent7d228473719e51995d3ebb497c53c93959e8b58b (diff)
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>
-rw-r--r--src/corelib/CMakeLists.txt1
-rw-r--r--src/corelib/global/qexceptionhandling.cpp20
-rw-r--r--src/corelib/global/qexceptionhandling.h45
-rw-r--r--src/corelib/global/qglobal.cpp15
-rw-r--r--src/corelib/global/qglobal.h27
5 files changed, 67 insertions, 41 deletions
diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt
index dc15ec831f..50b9009f8d 100644
--- a/src/corelib/CMakeLists.txt
+++ b/src/corelib/CMakeLists.txt
@@ -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
diff --git a/src/corelib/global/qexceptionhandling.cpp b/src/corelib/global/qexceptionhandling.cpp
new file mode 100644
index 0000000000..f74eb49546
--- /dev/null
+++ b/src/corelib/global/qexceptionhandling.cpp
@@ -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
diff --git a/src/corelib/global/qexceptionhandling.h b/src/corelib/global/qexceptionhandling.h
new file mode 100644
index 0000000000..aca8de9003
--- /dev/null
+++ b/src/corelib/global/qexceptionhandling.h
@@ -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
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 6acfefd771..de28cd87af 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -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>
@@ -2641,16 +2636,6 @@ QByteArray QSysInfo::bootUniqueId()
*/
/*
- \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
qsimplerichtext.cpp and qgfxraster_qws.cpp
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index f0295b70f5..13452bf22a 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -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>