From 10430d36ffef34142a44c92314d3a1ee160f6e67 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 31 Aug 2023 19:25:59 +0200 Subject: [PATCH] TaskTree: Add static asserts to onStorage{Setup,Done} handlers Require const reference for onStorageDone() handler. Change-Id: Iad333c04a78962a3361635900027bd4d41abc319 Reviewed-by: Reviewed-by: hjk --- src/libs/solutions/tasking/tasktree.h | 10 ++++++++++ tests/auto/solutions/tasking/tst_tasking.cpp | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libs/solutions/tasking/tasktree.h b/src/libs/solutions/tasking/tasktree.h index 32252bcc83b..5e1226eb2c4 100644 --- a/src/libs/solutions/tasking/tasktree.h +++ b/src/libs/solutions/tasking/tasktree.h @@ -413,11 +413,21 @@ public: template void onStorageSetup(const TreeStorage &storage, StorageHandler &&handler) { + constexpr bool isInvokable = std::is_invocable_v, + StorageStruct &>; + static_assert(isInvokable, + "Storage setup handler needs to take (Storage &) as an argument. " + "The passed handler doesn't fulfill these requirements."); setupStorageHandler(storage, wrapHandler(std::forward(handler)), {}); } template void onStorageDone(const TreeStorage &storage, StorageHandler &&handler) { + constexpr bool isInvokable = std::is_invocable_v, + const StorageStruct &>; + static_assert(isInvokable, + "Storage done handler needs to take (const Storage &) as an argument. " + "The passed handler doesn't fulfill these requirements."); setupStorageHandler(storage, {}, wrapHandler(std::forward(handler))); } diff --git a/tests/auto/solutions/tasking/tst_tasking.cpp b/tests/auto/solutions/tasking/tst_tasking.cpp index 63302c6dc31..57d95a5f4de 100644 --- a/tests/auto/solutions/tasking/tst_tasking.cpp +++ b/tests/auto/solutions/tasking/tst_tasking.cpp @@ -550,7 +550,7 @@ void tst_Tasking::testTree_data() }; taskTree.setRecipe(nestedRoot); CustomStorage *activeStorage = storage.activeStorage(); - const auto collectSubLog = [activeStorage](CustomStorage &subTreeStorage){ + const auto collectSubLog = [activeStorage](const CustomStorage &subTreeStorage){ activeStorage->m_log += subTreeStorage.m_log; }; taskTree.onStorageDone(storage, collectSubLog); @@ -2244,7 +2244,9 @@ void tst_Tasking::testTree() TaskTree taskTree({testData.root.withTimeout(1000ms)}); QCOMPARE(taskTree.taskCount() - 1, testData.taskCount); // -1 for the timeout task above Log actualLog; - const auto collectLog = [&actualLog](CustomStorage &storage) { actualLog = storage.m_log; }; + const auto collectLog = [&actualLog](const CustomStorage &storage) { + actualLog = storage.m_log; + }; taskTree.onStorageDone(testData.storage, collectLog); const OnDone result = taskTree.runBlocking() ? OnDone::Success : OnDone::Failure; QCOMPARE(taskTree.isRunning(), false); @@ -2278,7 +2280,7 @@ void tst_Tasking::storageDestructor() setupCalled = true; }; bool doneCalled = false; - const auto doneHandler = [&doneCalled](CustomStorage &) { + const auto doneHandler = [&doneCalled](const CustomStorage &) { doneCalled = true; }; QCOMPARE(CustomStorage::instanceCount(), 0);