From 8fdcda4dac3804006e870cb8cec3e85ea803d70f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 21 Dec 2024 12:08:32 -0300 Subject: [PATCH] Replace qTerminate() with std::terminate() and mark it for removal It was used by the QT_TERMINATE_ON_EXCEPTION macro, introduced in 2012, to support pre-C++11 noexcept semantics. That macro was removed for Qt 6.8 in commit 9b2ae564a59656d9cf49b141e70f5958b4fb79a4. This commit amends that removing the definition of qTerminate() immediately in Qt 6.9 (it was an \internal function). Change-Id: I9682121c04fafb3676b0fffd9f5ac999e7603c84 Reviewed-by: Ahmad Samir (cherry picked from commit b8f84fd1e2af38ece89d60619bf93e7af34433ab) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/CMakeLists.txt | 2 +- src/corelib/compat/removed_api.cpp | 9 +++++++++ .../code/src_corelib_global_qglobal.cpp | 4 ---- src/corelib/global/qexceptionhandling.cpp | 20 ------------------- src/corelib/global/qexceptionhandling.h | 5 ++++- src/corelib/thread/qthread_unix.cpp | 2 +- src/testlib/qtestresult.cpp | 2 +- 7 files changed, 16 insertions(+), 28 deletions(-) delete mode 100644 src/corelib/global/qexceptionhandling.cpp diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 6b6836df811..df7aa0eed2b 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -49,7 +49,7 @@ qt_internal_add_module(Core global/qcontainerinfo.h global/qdarwinhelpers.h global/qendian.cpp global/qendian.h global/qendian_p.h - global/qexceptionhandling.cpp global/qexceptionhandling.h + global/qexceptionhandling.h global/qflags.h global/qfloat16.cpp global/qfloat16.h global/qforeach.h diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index bdb811a1d0d..751c1995eda 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -1248,6 +1248,15 @@ QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData) noexcept #include "qchar.h" // inlined API + +#include "qexceptionhandling.h" + +Q_NORETURN void qTerminate() noexcept +{ + std::terminate(); +} + + #include "qmetatype.h" bool QMetaType::isRegistered() const diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp index 25d3abf67ea..393bd5778f1 100644 --- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -686,10 +686,6 @@ bool readConfiguration(const QFile &file) process(ch); // ERROR: ch is copied from deleted memory //! [as-const-4] -//! [qterminate] - try { expr; } catch(...) { qTerminate(); } -//! [qterminate] - //! [qdecloverride] // generate error if this doesn't actually override anything: virtual void MyWidget::paintEvent(QPaintEvent*) override; diff --git a/src/corelib/global/qexceptionhandling.cpp b/src/corelib/global/qexceptionhandling.cpp deleted file mode 100644 index f74eb495464..00000000000 --- a/src/corelib/global/qexceptionhandling.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 - -QT_BEGIN_NAMESPACE - -/* - \internal - Allows you to call std::terminate() without including . - 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 index 7ffd0798f6f..6c547a90630 100644 --- a/src/corelib/global/qexceptionhandling.h +++ b/src/corelib/global/qexceptionhandling.h @@ -22,7 +22,6 @@ QT_BEGIN_NAMESPACE 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 @@ -35,6 +34,10 @@ Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept; # define QT_RETHROW throw #endif +#if QT_CORE_REMOVED_SINCE(6, 9) +Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept; +#endif + QT_END_NAMESPACE #endif // QEXCEPTIONHANDLING_H diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 926b7aea400..fc9ab3aa1a6 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -319,7 +319,7 @@ void terminate_on_exception(T &&t) throw; #endif // __GLIBCXX__ } catch (...) { - qTerminate(); + std::terminate(); } #endif // QT_NO_EXCEPTIONS } diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index 4a6fb5918d7..39b4c0559d9 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -43,7 +43,7 @@ namespace QTest }(); if (failed && fatalFailure) - qTerminate(); + std::terminate(); Internal::failed = failed; }