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,37 +646,93 @@ TEST(span_test, from_container_constructor)
} }
} }
TEST(span_test, from_convertible_span_constructor){{span<DerivedClass> avd; TEST(span_test, from_convertible_span_constructor)
span<const DerivedClass> avcd = avd;
static_cast<void>(avcd);
}
{ {
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;
static_cast<void>(avcd);
}
{
std::array<DerivedClass, 2> arr{};
span<DerivedClass, 2> 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> 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<DerivedClass> avd;
span<BaseClass> avb = avd; span<BaseClass> avb = avd;
static_cast<void>(avb); static_cast<void>(avb);
#endif }
}
#ifdef CONFIRM_COMPILATION_ERRORS {
{
span<int> s; span<int> s;
span<unsigned int> s2 = s; span<unsigned int> s2 = s;
static_cast<void>(s2); static_cast<void>(s2);
} }
{ {
span<int> s; span<int> s;
span<const unsigned int> s2 = s; span<const unsigned int> s2 = s;
static_cast<void>(s2); static_cast<void>(s2);
} }
{ {
span<int> s; span<int> s;
span<short> s2 = s; span<short> s2 = s;
static_cast<void>(s2); static_cast<void>(s2);
} }
#endif #endif
} }