summaryrefslogtreecommitdiff
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 13:40:33 +0000
commitbc99032f9dc7b222b98ab135c75a2bc62cb455c8 (patch)
tree798f2328f460743f5352c350072928c0cccc9b9c
parent9ad76503b1e301a64637b3a3073e963d962e642f (diff)
downloadqttools-bc99032f9dc7b222b98ab135c75a2bc62cb455c8.tar.gz
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 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.