add some span test for constructor from other span (#1093)

More combinations with dynamic_extent or fixed extent for higher coverage.
This commit is contained in:
Werner Henze 2023-02-17 22:05:40 +01:00 committed by GitHub
parent 743939744c
commit 9851b94d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -646,20 +646,76 @@ TEST(span_test, from_container_constructor)
} }
} }
TEST(span_test, from_convertible_span_constructor){{span<DerivedClass> avd; TEST(span_test, from_convertible_span_constructor)
{
const auto terminateHandler = std::set_terminate([] {
std::cerr << "Expected Death. from_convertible_span_constructor";
std::abort();
});
const auto expected = GetExpectedDeathString(terminateHandler);
{
span<DerivedClass> avd;
span<const DerivedClass> avcd = avd; span<const DerivedClass> avcd = avd;
static_cast<void>(avcd); static_cast<void>(avcd);
} }
{ {
#ifdef CONFIRM_COMPILATION_ERRORS std::array<DerivedClass, 2> arr{};
span<DerivedClass> avd; span<DerivedClass, 2> avd{arr};
span<BaseClass> avb = avd; span<const DerivedClass, 2> avcd = avd;
static_cast<void>(avb); static_cast<void>(avcd);
#endif }
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass, 2> avd{arr};
span<const DerivedClass> avcd = avd;
static_cast<void>(avcd);
}
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass> avd{arr};
span<const DerivedClass, 2> avcd{avd};
static_cast<void>(avcd);
}
{
std::array<DerivedClass, 1> arr{};
span<DerivedClass> avd{arr};
using T = span<const DerivedClass, 2>;
EXPECT_DEATH(T{avd}, expected);
} }
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass> avd{arr};
span<const DerivedClass, 2> avcd = avd;
static_cast<void>(avcd);
}
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass, 2> avd{arr};
span<const DerivedClass, 1> avcd = avd;
static_cast<void>(avcd);
}
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass, 2> avd{arr};
span<const DerivedClass, 3> avcd = avd;
static_cast<void>(avcd);
}
{
span<DerivedClass> avd;
span<BaseClass> avb = avd;
static_cast<void>(avb);
}
{ {
span<int> s; span<int> s;
span<unsigned int> s2 = s; span<unsigned int> s2 = s;