mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
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:
parent
743939744c
commit
9851b94d7e
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user