Index: source/ps/Future.h =================================================================== --- source/ps/Future.h +++ source/ps/Future.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -280,7 +280,8 @@ template PackagedTask Future::Wrap(T&& func) { - static_assert(std::is_convertible_v, ResultType>, "The return type of the wrapped function cannot be converted to the type of the Future."); + static_assert(std::is_same_v, ResultType>, + "The return type of the wrapped function is not the same as the type of the Future."); m_SharedState = std::make_shared(std::move(func)); return PackagedTask(m_SharedState); } Index: source/ps/tests/test_Future.h =================================================================== --- source/ps/tests/test_Future.h +++ source/ps/tests/test_Future.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -54,14 +54,6 @@ TS_ASSERT_EQUALS(future.Get(), 1); } - // Convertible type. - { - Future future; - std::function task = future.Wrap([]() -> u8 { return 1; }); - task(); - TS_ASSERT_EQUALS(future.Get(), 1); - } - static int destroyed = 0; // No trivial constructor or destructor. Also not copiable. struct NonDef @@ -80,21 +72,21 @@ TS_ASSERT_EQUALS(destroyed, 0); { Future future; - std::function task = future.Wrap([]() { return 1; }); + std::function task = future.Wrap([]() { return NonDef{1}; }); task(); TS_ASSERT_EQUALS(future.Get().value, 1); } TS_ASSERT_EQUALS(destroyed, 1); { Future future; - std::function task = future.Wrap([]() { return 1; }); + std::function task = future.Wrap([]() { return NonDef{1}; }); } TS_ASSERT_EQUALS(destroyed, 1); /** * TODO: find a way to test this { Future future; - std::function task = future.Wrap([]() { return 1; }); + std::function task = future.Wrap([]() { return NonDef{1}; }); future.CancelOrWait(); TS_ASSERT_THROWS(future.Get(), const Future::BadFutureAccess&); }