summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2020-01-30 12:46:47 +0200
committerKari Oikarinen <kari.oikarinen@qt.io>2020-02-01 11:07:08 +0200
commit89f443dfbc980313f19cc8c6a205491a41c9926a (patch)
tree2f254ac396ea49feab31db5f6c73acc40e3f23b1 /src
parentbeede51bca1a43befe42499ad784af57d2450162 (diff)
QScopeGuard: Fix build failures with qScopeGuard()
Partially reverts 4f077b7e5ff1081afc0e362bdab6522c2b7ee43b. Can't overload with forwarding references and lvalue references. Use a single forwarding reference overload, but take care of not trying to create a QScopeGuard of reference type and forward instead of moving. Add tests to ensure calling with both lvalues and rvalues is possible. Change-Id: Ia034afe0a8feb08246c2c7c154a85cae37421c98 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qscopeguard.h15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/corelib/tools/qscopeguard.h b/src/corelib/tools/qscopeguard.h
index 4d2e715df1..6a5bc6cc61 100644
--- a/src/corelib/tools/qscopeguard.h
+++ b/src/corelib/tools/qscopeguard.h
@@ -43,6 +43,8 @@
#include <QtCore/qglobal.h>
+#include <type_traits>
+#include <utility>
QT_BEGIN_NAMESPACE
@@ -98,18 +100,9 @@ template <typename F>
#if __has_cpp_attribute(nodiscard)
Q_REQUIRED_RESULT
#endif
-QScopeGuard<F> qScopeGuard(F &&f)
+QScopeGuard<typename std::decay<F>::type> qScopeGuard(F &&f)
{
- return QScopeGuard<F>(std::move(f));
-}
-
-template <typename F>
-#if __has_cpp_attribute(nodiscard)
-Q_REQUIRED_RESULT
-#endif
-QScopeGuard<F> qScopeGuard(const F &f)
-{
- return QScopeGuard<F>(f);
+ return QScopeGuard<typename std::decay<F>::type>(std::forward<F>(f));
}
QT_END_NAMESPACE