summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-01-24 16:47:18 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-01-26 20:45:52 +0000
commit8134b35f2f199b0d704f84b76ad910e1425997c7 (patch)
treece8ac673d445538d466430c73c5e5d2938669e60
parenteae03b13ea5463906d88dea6f3ebf2c7f1747ce4 (diff)
HelpEngineWrapper: fix API susceptible to GCC 13 -Wdangling-reference
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 <jaroslaw.kobus@qt.io> (cherry picked from commit 14fe0bbea5b04dff01495e815b33a0a1dd2e191a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/assistant/assistant/helpenginewrapper.cpp5
-rw-r--r--src/assistant/assistant/helpenginewrapper.h3
2 files changed, 7 insertions, 1 deletions
diff --git a/src/assistant/assistant/helpenginewrapper.cpp b/src/assistant/assistant/helpenginewrapper.cpp
index bf30df306..cc07a9b63 100644
--- a/src/assistant/assistant/helpenginewrapper.cpp
+++ b/src/assistant/assistant/helpenginewrapper.cpp
@@ -107,6 +107,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 b2728ce78..3fa7327a5 100644
--- a/src/assistant/assistant/helpenginewrapper.h
+++ b/src/assistant/assistant/helpenginewrapper.h
@@ -64,7 +64,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.