From de715111b5812151a297e0c6c3c0ad496ea8667c Mon Sep 17 00:00:00 2001 From: Frans-Willem Hardijzer Date: Sat, 9 Dec 2017 23:41:23 +0100 Subject: [PATCH 1/2] Fix reduction of future> in case of exception. Attempted to keep code regarding of future> as close as possible to future> to prevent similar errors. --- stlab/concurrency/future.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stlab/concurrency/future.hpp b/stlab/concurrency/future.hpp index b1956fb6a..51d2c16f7 100644 --- a/stlab/concurrency/future.hpp +++ b/stlab/concurrency/future.hpp @@ -1574,7 +1574,15 @@ struct value_setter> template static void set(shared_base> &sb, F& f, Args&&... args) { - sb._result = f(std::forward(args)...).then([_p = sb.shared_from_this()]() { + sb._result = f(std::forward(args)...).recover([_p = sb.shared_from_this()](future f) { + if (f.error()) + { + _p->_error = std::move(f.error().value()); + value_setter::proceed(*_p); + throw future_error(future_error_codes::reduction_failed); + } + return; + }).then([_p = sb.shared_from_this()]() { proceed(*_p); }); } From 6cd28a9db7c0cff2d7b5bbe5af8021553eef028e Mon Sep 17 00:00:00 2001 From: Frans-Willem Hardijzer Date: Sat, 9 Dec 2017 23:42:30 +0100 Subject: [PATCH 2/2] Remove unnecesarry semicolons, to keep G++'s pedantic mode happy. --- stlab/concurrency/future.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stlab/concurrency/future.hpp b/stlab/concurrency/future.hpp index 51d2c16f7..42d3b54f9 100644 --- a/stlab/concurrency/future.hpp +++ b/stlab/concurrency/future.hpp @@ -327,7 +327,7 @@ struct shared_base> : std::enable_shared_from_this auto reduce(R&& r) { return std::forward(r); - }; + } auto reduce(future>&& r) -> future; @@ -448,7 +448,7 @@ struct shared_base> : std::enable_shared_from_this< template auto reduce(R&& r) { return std::forward(r); - }; + } template auto reduce(future>&& r) -> future; @@ -537,7 +537,7 @@ struct shared_base : std::enable_shared_from_this> { template auto reduce(R&& r) { return std::forward(r); - }; + } auto reduce(future>&& r) -> future;