diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 994c631d76c..cc5f442d947 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -925,15 +925,11 @@ std::shared_ptr qobject_pointer_cast(std::shared_ptr &&src) using element_type = typename std::shared_ptr::element_type; auto castResult = qobject_cast(src.get()); if (castResult) { - auto result = std::shared_ptr(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(std::exchange(src, nullptr), castResult); } return std::shared_ptr(); }