Details
-
Task
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
Description
When using optional types in data functions and directly assigning std::nullopt through operator <<, like this:
void TestOptional::optional_data() { QTest::addColumn<std::optional<int>>("optInteger"); auto retNullopt = []() -> std::optional<int> { return std::nullopt; }; std::optional<int> a = 1; QTest::newRow("ok1") << a; QTest::newRow("nullopt-ok") << retNullopt(); QTest::newRow("nullopt-err") << std::nullopt; }
QTest will complain like this:
QDEBUG : TestOptional::optional() expected data of type 'std::optional<int>', got 'std::nullopt_t' for element 0 of data with tag 'nullopt-err' QFATAL : TestOptional::optional() ASSERT: "false" in file /home/ddob/qt/qt6/qtbase/src/testlib/qtestdata.cpp, line 69 FAIL! : TestOptional::optional() Received a fatal error. Loc: [/home/ddob/qt/qt6/qtbase/src/testlib/qtestdata.cpp(69)]
When wrapping the std::nullopt through a function call it works again. I think having this implicit conversion seems logical. The same holds true for assigning the underlying type. QTest just strictly expects to receive the correct types but it's annoying for the std::nullopt case.
Example attached.