[libcxx-commits] [PATCH] D71994: SFINAE span default constructor on Extent == 0
Michael Schellenberger Costa via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 12 12:29:02 PDT 2020
miscco updated this revision to Diff 250022.
miscco added a comment.
Do not require concepts
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71994/new/
https://reviews.llvm.org/D71994
Files:
libcxx/include/span
libcxx/test/std/containers/views/span.cons/default.fail.cpp
libcxx/test/std/containers/views/span.cons/default.pass.cpp
Index: libcxx/test/std/containers/views/span.cons/default.pass.cpp
===================================================================
--- libcxx/test/std/containers/views/span.cons/default.pass.cpp
+++ libcxx/test/std/containers/views/span.cons/default.pass.cpp
@@ -13,11 +13,28 @@
// constexpr span() noexcept;
#include <span>
+
#include <cassert>
+#include <type_traits>
#include <string>
+#include <version>
#include "test_macros.h"
+#ifdef __cpp_lib_concepts
+#include <concepts>
+#endif // __cpp_lib_concepts
+
+static_assert( std::is_default_constructible_v<std::span<int, std::dynamic_extent>>, "");
+static_assert( std::is_default_constructible_v<std::span<int, 0>>, "");
+static_assert(!std::is_default_constructible_v<std::span<int, 2>>, "");
+
+#ifdef __cpp_lib_concepts
+static_assert( std::default_constructible<std::span<int, std::dynamic_extent>>, "");
+static_assert( std::default_constructible<std::span<int, 0>>, "");
+static_assert(!std::default_constructible<std::span<int, 2>>, "");
+#endif // __cpp_lib_concepts
+
void checkCV()
{
// Types the same (dynamic sized)
Index: libcxx/test/std/containers/views/span.cons/default.fail.cpp
===================================================================
--- libcxx/test/std/containers/views/span.cons/default.fail.cpp
+++ libcxx/test/std/containers/views/span.cons/default.fail.cpp
@@ -13,7 +13,7 @@
// constexpr span() noexcept;
//
// Remarks: This constructor shall not participate in overload resolution
-// unless Extent <= 0 is true.
+// unless Extent == 0 || Extent == dynamic_extent is true.
#include <span>
@@ -24,10 +24,7 @@
int main(int, char**)
{
- std::span<int, 2> s; // expected-error-re at span:* {{static_assert failed{{( due to requirement '.*')?}} "Can't default construct a statically sized span with size > 0"}}
-
-// TODO: This is what I want:
-// eXpected-error {{no matching constructor for initialization of 'std::span<int, 2>'}}
+ std::span<int, 2> s; // expected-error {{no matching constructor for initialization of 'std::span<int, 2>'}}
return 0;
}
Index: libcxx/include/span
===================================================================
--- libcxx/include/span
+++ libcxx/include/span
@@ -208,8 +208,8 @@
static constexpr size_type extent = _Extent;
// [span.cons], span constructors, copy, assignment, and destructor
- _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}
- { static_assert(_Extent == 0, "Can't default construct a statically sized span with size > 0"); }
+ template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr>
+ _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {}
constexpr span (const span&) noexcept = default;
constexpr span& operator=(const span&) noexcept = default;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71994.250022.patch
Type: text/x-patch
Size: 2851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200312/17b25ba0/attachment.bin>
More information about the libcxx-commits
mailing list