diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2016-08-04 14:16:05 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-08-05 07:15:28 +0000 |
commit | 48deab9b69afc8d613e2b22dacd138be7c8c51a8 (patch) | |
tree | 9ad1e9c882024110dae744f21ba1d6f22adb52de /src/qml/qml/qqmltypeloader.cpp | |
parent | fe663bf863ffd6085c3022db7e9a923688befeb6 (diff) |
Fix QML engine in MSVC debug builds
In debug builds MSVC does not do return value optimization and therefore
would call the destructor and thus callback on the temporary, a rather
unwanted side-effect. Let's use a different approach that is guaranteed
to avoid temporaries.
Change-Id: I534258754331495db38cd7960b88bf4bec38ddba
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/qml/qqmltypeloader.cpp')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 38715f6cd3..06cabfeb65 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -121,19 +121,17 @@ namespace { ~LockHolder() { lock.unlock(); } }; - struct DeferredCall + struct Defer { std::function<void()> callback; - ~DeferredCall() { callback(); } + template <typename Callback> + Defer(Callback &&cb) + : callback(cb) + {} + ~Defer() { callback(); } + Defer(const Defer &) = delete; + Defer &operator=(const Defer &) = delete; }; - - template <typename Callback> - DeferredCall defer(Callback &&cb) - { - DeferredCall c; - c.callback = std::move(cb); - return c; - } } #ifndef QT_NO_NETWORK @@ -2168,7 +2166,7 @@ void QQmlTypeData::createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeName void QQmlTypeData::done() { - auto cleanup = defer([this]{ + Defer cleanup([this]{ m_document.reset(); m_typeReferences.clear(); if (isError()) |