From 1a905cbd4f2f9c1ccb477a6a98ba23a6c24e4ca4 Mon Sep 17 00:00:00 2001 From: Egor Krugletsov <74310448+Poldraunic@users.noreply.github.com> Date: Sat, 24 Aug 2024 10:01:08 +0300 Subject: [PATCH] Use std::shared_ptr for PromiseValue::m_data instead of QSharedPoitner (#60) In optimized builds (such as -O2) GCC emits "maybe-uninitialized" warning for QSharedPointer::d. This happens only for optimized builds because that is when GCC tracks lifetimes[1]. In a project with lots of QtPromise uses this produces a heap of bogus warnings. This warning has been previously reported to a Qt team, but they're confident it is a compiler bug[2][3]. However, this is a second time and issue raised with QSharedPointer and warnings to it. The first time it was addressed here: https://github.com/simonbrunel/qtpromise/pull/34. [1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmaybe-uninitialized [2] https://bugreports.qt.io/browse/QTBUG-14637 [3] https://bugreports.qt.io/browse/QTBUG-77641 --- src/qtpromise/qpromise_p.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/qtpromise/qpromise_p.h b/src/qtpromise/qpromise_p.h index 2b5e674..f18eaba 100644 --- a/src/qtpromise/qpromise_p.h +++ b/src/qtpromise/qpromise_p.h @@ -20,6 +20,8 @@ #include #include +#include + namespace QtPromise { template @@ -92,13 +94,13 @@ class PromiseValue { public: PromiseValue() { } - PromiseValue(const T& data) : m_data(QSharedPointer::create(data)) { } - PromiseValue(T&& data) : m_data(QSharedPointer::create(std::forward(data))) { } - bool isNull() const { return m_data.isNull(); } + PromiseValue(const T& data) : m_data(std::make_shared(data)) { } + PromiseValue(T&& data) : m_data(std::make_shared(std::forward(data))) { } + bool isNull() const { return m_data == nullptr; } const T& data() const { return *m_data; } private: - QSharedPointer m_data; + std::shared_ptr m_data; }; class PromiseError