Fix reference to a dead temporary
NoDefaultConstructorRef1 was taking a reference of the input, which meant in the first test it would get a reference to the temporary created by the 1 literal. A temporary that would be out of scope by the time we check its value. Instead add a test with unique_ptr to test we can pass movable temporaries. Change-Id: I6b02377dfe30c82b6e71bfb3353a81ad81558ed3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0e2c013a45
commit
cf7d990a48
@ -40,6 +40,7 @@
|
||||
#include "nontracked.h"
|
||||
#include "wrapper.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
@ -232,6 +233,12 @@ struct NoDefaultConstructorRRef1
|
||||
int &i;
|
||||
NoDefaultConstructorRRef1(int &&i) : i(i) {}
|
||||
};
|
||||
|
||||
struct NoDefaultConstructorRRef2
|
||||
{
|
||||
std::unique_ptr<int> i;
|
||||
NoDefaultConstructorRRef2(std::unique_ptr<int> &&i) : i(std::move(i)) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
void tst_QSharedPointer::basics_data()
|
||||
@ -1820,14 +1827,19 @@ void tst_QSharedPointer::creatingVariadic()
|
||||
QCOMPARE(&ptr->i, &i);
|
||||
}
|
||||
{
|
||||
NoDefaultConstructorRRef1(1); // control check
|
||||
QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1);
|
||||
QCOMPARE(ptr->i, 1);
|
||||
|
||||
NoDefaultConstructorRRef1(std::move(i)); // control check
|
||||
ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i));
|
||||
QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i));
|
||||
QCOMPARE(ptr->i, i);
|
||||
}
|
||||
{
|
||||
NoDefaultConstructorRRef2(std::unique_ptr<int>(new int(1))); // control check
|
||||
QSharedPointer<NoDefaultConstructorRRef2> ptr = QSharedPointer<NoDefaultConstructorRRef2>::create(std::unique_ptr<int>(new int(1)));
|
||||
QCOMPARE(*ptr->i, 1);
|
||||
|
||||
std::unique_ptr<int> p(new int(i));
|
||||
ptr = QSharedPointer<NoDefaultConstructorRRef2>::create(std::move(p));
|
||||
QCOMPARE(*ptr->i, i);
|
||||
}
|
||||
{
|
||||
QString text("Hello, World");
|
||||
NoDefaultConstructorRef2(text, 1); // control check
|
||||
|
Loading…
x
Reference in New Issue
Block a user