Skip to content

Commit

Permalink
Use std::shared_ptr for PromiseValue<T>::m_data instead of QSharedPoi…
Browse files Browse the repository at this point in the history
…tner<T>

In optimized builds (such as -O2) GCC emits "maybe-uninitialized" warning for QSharedPointer<T>::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: simonbrunel#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
  • Loading branch information
Poldraunic authored and simonbrunel committed Aug 24, 2024
1 parent 1403139 commit 0bc9d4d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/qtpromise/qpromise_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <QtCore/QVariant>
#include <QtCore/QVector>

#include <memory>

namespace QtPromise {

template<typename T>
Expand Down Expand Up @@ -92,13 +94,13 @@ class PromiseValue
{
public:
PromiseValue() { }
PromiseValue(const T& data) : m_data(QSharedPointer<T>::create(data)) { }
PromiseValue(T&& data) : m_data(QSharedPointer<T>::create(std::forward<T>(data))) { }
bool isNull() const { return m_data.isNull(); }
PromiseValue(const T& data) : m_data(std::make_shared<T>(data)) { }
PromiseValue(T&& data) : m_data(std::make_shared<T>(std::forward<T>(data))) { }
bool isNull() const { return m_data == nullptr; }
const T& data() const { return *m_data; }

private:
QSharedPointer<T> m_data;
std::shared_ptr<T> m_data;
};

class PromiseError
Expand Down

0 comments on commit 0bc9d4d

Please sign in to comment.