From bc99032f9dc7b222b98ab135c75a2bc62cb455c8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 24 Jan 2023 16:47:18 +0100 Subject: HelpEngineWrapper: fix API susceptible to GCC 13 -Wdangling-reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 13 currently assumes that the temporary argument (the default value) ends up embedded in the result, and warns: helpviewer.cpp:393:34: error: possibly dangling reference to a temporary [-Werror=dangling-reference] 393 | const HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); | ^~~~~~~~~~ helpviewer.cpp:393:74: note: the temporary was destroyed at the end of the full expression ‘Qt6::HelpEngineWrapper::instance(Qt6::QString())’ 393 | const HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ An attempt to fix the issue by passing the QString by value made it worse, as all calls threw the warning then, including those that pass a QString instead of relying on the defaulted argument. So, heed QTBUG-98117 and overload instead of using default arguments. Having the nullary overload in the same TU as the unary one seems to make GCC shut up about the False Positive dangling. Task-number: QTBUG-98117 Change-Id: I69da70dfbf996ab923078631031f6f3c7a5cfcbe Reviewed-by: Jarek Kobus (cherry picked from commit 14fe0bbea5b04dff01495e815b33a0a1dd2e191a) Reviewed-by: Qt Cherry-pick Bot --- src/assistant/assistant/helpenginewrapper.cpp | 5 +++++ src/assistant/assistant/helpenginewrapper.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/assistant/assistant/helpenginewrapper.cpp b/src/assistant/assistant/helpenginewrapper.cpp index b08bb213e..675655fd0 100644 --- a/src/assistant/assistant/helpenginewrapper.cpp +++ b/src/assistant/assistant/helpenginewrapper.cpp @@ -85,6 +85,11 @@ private: HelpEngineWrapper *HelpEngineWrapper::helpEngineWrapper = nullptr; +HelpEngineWrapper &HelpEngineWrapper::instance() +{ + return instance({}); +} + HelpEngineWrapper &HelpEngineWrapper::instance(const QString &collectionFile) { TRACE_OBJ diff --git a/src/assistant/assistant/helpenginewrapper.h b/src/assistant/assistant/helpenginewrapper.h index 177d281a8..f0e7b84aa 100644 --- a/src/assistant/assistant/helpenginewrapper.h +++ b/src/assistant/assistant/helpenginewrapper.h @@ -40,7 +40,8 @@ class HelpEngineWrapper : public QObject Q_DISABLE_COPY(HelpEngineWrapper) friend class TimeoutForwarder; public: - static HelpEngineWrapper &instance(const QString &collectionFile = QString()); + static HelpEngineWrapper &instance(); + static HelpEngineWrapper &instance(const QString &collectionFile); static void removeInstance(); // Forwarded help engine member functions, possibly enriched. -- cgit v1.2.1