qGetPtrHelper: make it work with null d-pointers

operator-> comes with the precondition that the smart pointer
is not null. Having null d-pointers is a valid use case, so
enable it by using get() instead of operator->().

Change-Id: I78d77ca8c44e92a65ca98b15d0620bc3a1917ad2
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2020-06-08 16:48:15 +02:00
parent d7c75ee005
commit c208b648f9

View File

@ -1086,7 +1086,7 @@ for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
#endif
template <typename T> inline T *qGetPtrHelper(T *ptr) { return ptr; }
template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) -> decltype(ptr.get()) { return ptr.get(); }
// The body must be a statement:
#define Q_CAST_IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP