From 38bf6840e8589ebe22e8157aee79a57d9db9393d Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 5 Jun 2024 07:21:57 -0700 Subject: [libc++] Add missing noexcept to span constructor (#94381) Thanks to Marshall Clow for noticing. Fixes #94364 --- .../views/views.span/span.cons/span.pass.cpp | 145 +++++++++++---------- 1 file changed, 74 insertions(+), 71 deletions(-) (limited to 'libcxx/test') diff --git a/libcxx/test/std/containers/views/views.span/span.cons/span.pass.cpp b/libcxx/test/std/containers/views/views.span/span.cons/span.pass.cpp index edf983e..a1ac0dd 100644 --- a/libcxx/test/std/containers/views/views.span/span.cons/span.pass.cpp +++ b/libcxx/test/std/containers/views/views.span/span.cons/span.pass.cpp @@ -16,103 +16,106 @@ // Extent == dynamic_extent || Extent == OtherExtent is true, and // OtherElementType(*)[] is convertible to ElementType(*)[]. - #include #include #include #include "test_macros.h" -void checkCV() -{ - std::span< int> sp; -// std::span csp; - std::span< volatile int> vsp; -// std::span cvsp; +template +TEST_CONSTEXPR_CXX20 void check() { + // dynamic -> dynamic + { + { + std::span from; + std::span span{from}; + ASSERT_NOEXCEPT(std::span(from)); + assert(span.data() == nullptr); + assert(span.size() == 0); + } + { + From array[3] = {}; + std::span from(array); + std::span span{from}; + ASSERT_NOEXCEPT(std::span(from)); + assert(span.data() == array); + assert(span.size() == 3); + } + } - std::span< int, 0> sp0; -// std::span csp0; - std::span< volatile int, 0> vsp0; -// std::span cvsp0; + // static -> static + { + { + std::span from; + std::span span{from}; + ASSERT_NOEXCEPT(std::span(from)); + assert(span.data() == nullptr); + assert(span.size() == 0); + } -// dynamic -> dynamic { - std::span s1{ sp}; // a span pointing at int. - std::span< volatile int> s2{ sp}; // a span< volatile int> pointing at int. - std::span s3{ sp}; // a span pointing at int. - std::span s4{ vsp}; // a span pointing at volatile int. - assert(s1.size() + s2.size() + s3.size() + s4.size() == 0); + From array[3] = {}; + std::span from(array); + std::span span{from}; + ASSERT_NOEXCEPT(std::span(from)); + assert(span.data() == array); + assert(span.size() == 3); } + } -// static -> static + // static -> dynamic + { { - std::span s1{ sp0}; // a span pointing at int. - std::span< volatile int, 0> s2{ sp0}; // a span< volatile int> pointing at int. - std::span s3{ sp0}; // a span pointing at int. - std::span s4{ vsp0}; // a span pointing at volatile int. - assert(s1.size() + s2.size() + s3.size() + s4.size() == 0); + std::span from; + std::span span{from}; + ASSERT_NOEXCEPT(std::span(from)); + assert(span.data() == nullptr); + assert(span.size() == 0); } -// static -> dynamic { - std::span s1{ sp0}; // a span pointing at int. - std::span< volatile int> s2{ sp0}; // a span< volatile int> pointing at int. - std::span s3{ sp0}; // a span pointing at int. - std::span s4{ vsp0}; // a span pointing at volatile int. - assert(s1.size() + s2.size() + s3.size() + s4.size() == 0); + From array[3] = {}; + std::span from(array); + std::span span{from}; + ASSERT_NOEXCEPT(std::span(from)); + assert(span.data() == array); + assert(span.size() == 3); } + } -// dynamic -> static (not allowed) + // dynamic -> static (not allowed) } +template +TEST_CONSTEXPR_CXX20 void check_cvs() { + check(); -template -constexpr bool testConstexprSpan() -{ - std::span s0{}; - std::span s1{}; - std::span s2(s1); // static -> dynamic - ASSERT_NOEXCEPT(std::span {s0}); - ASSERT_NOEXCEPT(std::span{s1}); - ASSERT_NOEXCEPT(std::span {s1}); + check(); + check(); - return - s1.data() == nullptr && s1.size() == 0 - && s2.data() == nullptr && s2.size() == 0; -} - - -template -void testRuntimeSpan() -{ - std::span s0{}; - std::span s1{}; - std::span s2(s1); // static -> dynamic - ASSERT_NOEXCEPT(std::span {s0}); - ASSERT_NOEXCEPT(std::span{s1}); - ASSERT_NOEXCEPT(std::span {s1}); + check(); + check(); - assert(s1.data() == nullptr && s1.size() == 0); - assert(s2.data() == nullptr && s2.size() == 0); + check(); + check(); + check(); + check(); } +struct A {}; -struct A{}; - -int main(int, char**) -{ - static_assert(testConstexprSpan(), ""); - static_assert(testConstexprSpan(), ""); - static_assert(testConstexprSpan(), ""); - static_assert(testConstexprSpan(), ""); - - testRuntimeSpan(); - testRuntimeSpan(); - testRuntimeSpan(); - testRuntimeSpan(); - testRuntimeSpan(); +TEST_CONSTEXPR_CXX20 bool test() { + check_cvs(); + check_cvs(); + check_cvs(); + check_cvs(); + check_cvs(); + return true; +} - checkCV(); +int main(int, char**) { + static_assert(test()); + test(); return 0; } -- cgit v1.1