From 310b75e51995e8a9aeae0ea6c6d7922324453f57 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 25 Feb 2019 18:32:57 +0000 Subject: [PATCH] LWG3101 - span's Container constructors need another constraint. Reviewed as https://reviews.llvm.org/D57058. llvm-svn: 354805 --- libcxx/include/span | 14 -------- .../views/span.cons/container.fail.cpp | 27 +++------------ .../views/span.cons/container.pass.cpp | 33 +++---------------- 3 files changed, 10 insertions(+), 64 deletions(-) diff --git a/libcxx/include/span b/libcxx/include/span index 78340003445ad..0edf92c0a9fd8 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -225,20 +225,6 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span( array& __arr) noexcept : __data{__arr.data()} {} _LIBCPP_INLINE_VISIBILITY constexpr span(const array& __arr) noexcept : __data{__arr.data()} {} - template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span( _Container& __c, - enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) - : __data{_VSTD::data(__c)} - { _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (container)"); } - - template - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(const _Container& __c, - enable_if_t<__is_span_compatible_container::value, nullptr_t> = nullptr) - : __data{_VSTD::data(__c)} - { _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (const container)"); } - template inline _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _Extent>& __other, diff --git a/libcxx/test/std/containers/views/span.cons/container.fail.cpp b/libcxx/test/std/containers/views/span.cons/container.fail.cpp index d0fb5656d21e3..9bc13a610690a 100644 --- a/libcxx/test/std/containers/views/span.cons/container.fail.cpp +++ b/libcxx/test/std/containers/views/span.cons/container.fail.cpp @@ -16,6 +16,7 @@ // constexpr span(const Container& cont); // // Remarks: These constructors shall not participate in overload resolution unless: +// — extent == dynamic_extent, // — Container is not a specialization of span, // — Container is not a specialization of array, // — is_array_v is false, @@ -69,37 +70,28 @@ int main(int, char**) // Making non-const spans from const sources (a temporary binds to `const &`) { std::span s1{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s2{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s3{std::vector()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s4{std::vector()}; // expected-error {{no matching constructor for initialization of 'std::span'}} } // Missing size and/or data { std::span s1{NotAContainerNoData()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s2{NotAContainerNoData()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s3{NotAContainerNoSize()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s4{NotAContainerNoSize()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s5{NotAContainerPrivate()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s6{NotAContainerPrivate()}; // expected-error {{no matching constructor for initialization of 'std::span'}} // Again with the standard containers std::span s11{std::deque()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s12{std::deque()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s13{std::list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s14{std::list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s15{std::forward_list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s16{std::forward_list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} } // Not the same type { IsAContainer c; std::span s1{c}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s2{c}; // expected-error {{no matching constructor for initialization of 'std::span'}} } -// CV wrong (dynamically sized) +// CV wrong { IsAContainer c; IsAContainer cv; @@ -114,19 +106,10 @@ int main(int, char**) std::span< volatile int> s7{cv}; // expected-error {{no matching constructor for initialization of 'std::span'}} } -// CV wrong (statically sized) +// statically sized { - IsAContainer c; - IsAContainer cv; - IsAContainer< volatile int> v; - - std::span< int,1> s1{c}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span< int,1> s2{v}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span< int,1> s3{cv}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s4{v}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span s5{cv}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span< volatile int,1> s6{c}; // expected-error {{no matching constructor for initialization of 'std::span'}} - std::span< volatile int,1> s7{cv}; // expected-error {{no matching constructor for initialization of 'std::span'}} + IsAContainer c; + std::span s1{c}; // expected-error {{no matching constructor for initialization of 'std::span'}} } diff --git a/libcxx/test/std/containers/views/span.cons/container.pass.cpp b/libcxx/test/std/containers/views/span.cons/container.pass.cpp index 07aac9229f099..d42013bd268bb 100644 --- a/libcxx/test/std/containers/views/span.cons/container.pass.cpp +++ b/libcxx/test/std/containers/views/span.cons/container.pass.cpp @@ -16,6 +16,7 @@ // constexpr span(const Container& cont); // // Remarks: These constructors shall not participate in overload resolution unless: +// — extent == dynamic_extent, // — Container is not a specialization of span, // — Container is not a specialization of array, // — is_array_v is false, @@ -48,17 +49,12 @@ void checkCV() { std::vector v = {1,2,3}; -// Types the same (dynamic sized) +// Types the same { std::span< int> s1{v}; // a span< int> pointing at int. } -// Types the same (static sized) - { - std::span< int,3> s1{v}; // a span< int> pointing at int. - } - -// types different (dynamic sized) +// types different { std::span s1{v}; // a span pointing at int. std::span< volatile int> s2{v}; // a span< volatile int> pointing at int. @@ -66,24 +62,12 @@ void checkCV() std::span s4{v}; // a span pointing at int. } -// types different (static sized) - { - std::span s1{v}; // a span pointing at int. - std::span< volatile int,3> s2{v}; // a span< volatile int> pointing at int. - std::span< volatile int,3> s3{v}; // a span< volatile int> pointing at const int. - std::span s4{v}; // a span pointing at int. - } - // Constructing a const view from a temporary { std::span s1{IsAContainer()}; - std::span s2{IsAContainer()}; std::span s3{std::vector()}; - std::span s4{std::vector()}; (void) s1; - (void) s2; (void) s3; - (void) s4; } } @@ -92,11 +76,8 @@ template constexpr bool testConstexprSpan() { constexpr IsAContainer val{}; - std::span s1{val}; - std::span s2{val}; - return - s1.data() == val.getV() && s1.size() == 1 - && s2.data() == val.getV() && s2.size() == 1; + std::span s1{val}; + return s1.data() == val.getV() && s1.size() == 1; } @@ -107,12 +88,8 @@ void testRuntimeSpan() const IsAContainer cVal; std::span s1{val}; std::span s2{cVal}; - std::span s3{val}; - std::span s4{cVal}; assert(s1.data() == val.getV() && s1.size() == 1); assert(s2.data() == cVal.getV() && s2.size() == 1); - assert(s3.data() == val.getV() && s3.size() == 1); - assert(s4.data() == cVal.getV() && s4.size() == 1); } struct A{};