summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-07-02 08:55:14 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-09 04:33:57 +0000
commit20b805f30fa17272a680efb17e742148650a0f8f (patch)
treefc4ec8fbe7d42861688a87736b3a24eeef1e0df1 /src
parente4741830591cb45788753e07fcb5c281b13058e5 (diff)
Fix rvalue overload of qobject_pointer_cast for GCC 9.3
The code assumed that any C++ implementation would implement the resolution for LWG2996 in C++20 mode. While that may be the case in the future, the current state in GCC 9.3 as shipped in Ubuntu 20.04 LTS is that it doesn't, which leads to tst_qsharedpointer fail there. Fix by using the safe version of std::move, std::exchange, which guarantees the state of the src object, no matter what the callee does. Change-Id: Icc39b527df4d3a7b398ff2b44bcbdf9082b81f2f Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit 0632494bd47e924ce7914b6457791d4612599e5f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 994c631d76..cc5f442d94 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -925,15 +925,11 @@ std::shared_ptr<X> qobject_pointer_cast(std::shared_ptr<T> &&src)
using element_type = typename std::shared_ptr<X>::element_type;
auto castResult = qobject_cast<element_type *>(src.get());
if (castResult) {
- auto result = std::shared_ptr<X>(std::move(src), castResult);
-#if __cplusplus <= 201703L
// C++2a's move aliasing constructor will leave src empty.
// Before C++2a we don't really know if the compiler has support for it.
// The move aliasing constructor is the resolution for LWG2996,
// which does not impose a feature-testing macro. So: clear src.
- src.reset();
-#endif
- return result;
+ return std::shared_ptr<X>(std::exchange(src, nullptr), castResult);
}
return std::shared_ptr<X>();
}