Fix C++20 bugs and tests

This commit is contained in:
Dmitry Kobets
2021-12-01 14:21:02 -08:00
parent e0880931ae
commit 4430ba9663
10 changed files with 58 additions and 36 deletions
+11 -5
View File
@@ -128,16 +128,22 @@ TEST(at_tests, std_span)
std::vector<int> cvec{1, 2, 3, 4, 5};
std::span csp{cvec};
for (size_t i = 0, i < vec.size(); ++i)
for (gsl::index i = 0; i < gsl::narrow_cast<gsl::index>(vec.size()); ++i)
{
EXPECT_TRUE(&gsl::at(sp, i) == &vec[i]);
EXPECT_TRUE(&gsl::at(csp, i) == &cvec[i]);
EXPECT_TRUE(&gsl::at(sp, i) == &vec[gsl::narrow_cast<size_t>(i)]);
EXPECT_TRUE(&gsl::at(csp, i) == &cvec[gsl::narrow_cast<size_t>(i)]);
}
const auto terminateHandler = std::set_terminate([] {
std::cerr << "Expected Death. std_span";
std::abort();
});
const auto expected = GetExpectedDeathString(terminateHandler);
EXPECT_DEATH(gsl::at(sp, -1), expected);
EXPECT_DEATH(gsl::at(sp, sp.size()), expected);
EXPECT_DEATH(gsl::at(sp, gsl::narrow_cast<gsl::index>(sp.size())), expected);
EXPECT_DEATH(gsl::at(csp, -1), expected);
EXPECT_DEATH(gsl::at(csp, sp.size()), expected);
EXPECT_DEATH(gsl::at(csp, gsl::narrow_cast<gsl::index>(sp.size())), expected);
}
#endif // __cplusplus >= 202002L