mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-21 18:24:29 +08:00
Use std::shared_ptr for PromiseValue<T>::m_data instead of QSharedPoitner<T> (#60)
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: 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
This commit is contained in:
parent
14031392ac
commit
1a905cbd4f
@ -20,6 +20,8 @@
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QVector>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace QtPromise {
|
||||
|
||||
template<typename T>
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user