Skip to content

Commit b71dcbd

Browse files
author
Alex Damian
authored
Merge pull request #147 from accelerated/invalid-future
Fix validity check on generic futures when they are default constructed
2 parents 21215c3 + 342ba0e commit b71dcbd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

quantum/util/impl/quantum_generic_future_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ GenericFuture<T>::~GenericFuture()
178178
template <typename T>
179179
bool GenericFuture<T>::valid() const
180180
{
181-
return std::visit([](const auto& ctx)->bool { return ctx->valid(); }, _context);
181+
return std::visit([](const auto& ctx)->bool { return ctx ? ctx->valid() : false; }, _context);
182182
}
183183

184184
template <typename T>

tests/quantum_generic_future_tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ TEST(GenericFuture, WaitForIoFutureInCoroutine)
7676
return ioFuture.get() + 10;
7777
});
7878

79+
EXPECT_TRUE(threadFuture.valid());
80+
7981
EXPECT_EQ(43, threadFuture.get()); //block until value is available
8082
}
8183

@@ -98,4 +100,10 @@ TEST(GenericFuture, TestCopyable)
98100

99101
//read from the second future and we should throw
100102
EXPECT_THROW(v.back().get(), FutureAlreadyRetrievedException);
103+
}
104+
105+
TEST(GenericFuture, Invalid)
106+
{
107+
GenericFuture<int> future; //default constructed
108+
EXPECT_FALSE(future.valid());
101109
}

0 commit comments

Comments
 (0)