diff --git a/src/libs/solutions/tasking/tasktree.h b/src/libs/solutions/tasking/tasktree.h index 46c5f217a4c..3cdff6fb8ae 100644 --- a/src/libs/solutions/tasking/tasktree.h +++ b/src/libs/solutions/tasking/tasktree.h @@ -181,6 +181,8 @@ class Storage final : public StorageBase { public: Storage() : StorageBase(Storage::ctor(), Storage::dtor()) {} + Storage(const StorageStruct &data) + : StorageBase([data] { return new StorageStruct(data); }, Storage::dtor()) {} StorageStruct &operator*() const noexcept { return *activeStorage(); } StorageStruct *operator->() const noexcept { return activeStorage(); } StorageStruct *activeStorage() const { diff --git a/tests/auto/solutions/tasking/tst_tasking.cpp b/tests/auto/solutions/tasking/tst_tasking.cpp index d9badac13c4..5a0b7849a1d 100644 --- a/tests/auto/solutions/tasking/tst_tasking.cpp +++ b/tests/auto/solutions/tasking/tst_tasking.cpp @@ -120,6 +120,7 @@ private slots: void storageOperators(); void storageDestructor(); void storageZeroInitialization(); + void storageDataInitialization(); void nestedBrokenStorage(); void restart(); void destructorOfTaskEmittingDone(); @@ -4114,7 +4115,22 @@ void tst_Tasking::storageZeroInitialization() taskTree.runBlocking(); QVERIFY(defaultValue); - QCOMPARE(defaultValue, 0); + QCOMPARE(*defaultValue, 0); +} + +// This test ensures that the storage c'tor with data is initialized properly. +void tst_Tasking::storageDataInitialization() +{ + const Storage storage(42); + std::optional defaultValue; + + const auto onSetup = [storage, &defaultValue] { defaultValue = *storage; }; + + TaskTree taskTree({ storage, onGroupSetup(onSetup) }); + taskTree.runBlocking(); + + QVERIFY(defaultValue); + QCOMPARE(*defaultValue, 42); } // This test ensures that when a missing storage object inside the nested task tree is accessed