[libcxx-commits] [libcxx] 70d7bef - [libc++] Verify span and string_view are trivially copyable
Joe Loser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Oct 11 11:29:43 PDT 2021
Author: Joe Loser
Date: 2021-10-11T14:29:09-04:00
New Revision: 70d7bef1e8ef4bb5b0d3cb3c0d89b088103eb83d
URL: https://github.com/llvm/llvm-project/commit/70d7bef1e8ef4bb5b0d3cb3c0d89b088103eb83d
DIFF: https://github.com/llvm/llvm-project/commit/70d7bef1e8ef4bb5b0d3cb3c0d89b088103eb83d.diff
LOG: [libc++] Verify span and string_view are trivially copyable
Implement P2251 which requires `span` and `basic_string_view` to be
trivially copyable. They already are - this just adds tests to bind that
behavior.
Reviewed By: ldionne, Quuxplusone, Mordante, #libc
Differential Revision: https://reviews.llvm.org/D111197
Added:
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp
Modified:
libcxx/docs/Status/Cxx2bPapers.csv
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx2bPapers.csv b/libcxx/docs/Status/Cxx2bPapers.csv
index 44ef06b3c49a2..a6bc898effd5d 100644
--- a/libcxx/docs/Status/Cxx2bPapers.csv
+++ b/libcxx/docs/Status/Cxx2bPapers.csv
@@ -31,7 +31,7 @@
"`P1272 <https://wg21.link/P1272>`__","LWG","Byteswapping for fun&&nuf","October 2021","",""
"`P1675 <https://wg21.link/P1675>`__","LWG","``rethrow_exception`` must be allowed to copy","October 2021","",""
"`P2077 <https://wg21.link/P2077>`__","LWG","Heterogeneous erasure overloads for associative containers","October 2021","",""
-"`P2251 <https://wg21.link/P2251>`__","LWG","Require ``span`` & ``basic_string_view`` to be Trivially Copyable","October 2021","",""
+"`P2251 <https://wg21.link/P2251>`__","LWG","Require ``span`` & ``basic_string_view`` to be Trivially Copyable","October 2021","|Complete|","14.0"
"`P2301 <https://wg21.link/P2301>`__","LWG","Add a ``pmr`` alias for ``std::stacktrace``","October 2021","",""
"`P2321 <https://wg21.link/P2321>`__","LWG","``zip``","October 2021","",""
"`P2340 <https://wg21.link/P2340>`__","LWG","Clarifying the status of the 'C headers'","October 2021","",""
diff --git a/libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp b/libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp
new file mode 100644
index 0000000000000..bb30bb6aab5ee
--- /dev/null
+++ b/libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp
@@ -0,0 +1,18 @@
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// P2251 was voted into C++23, but is supported even in C++20 mode by all vendors.
+
+// <span>
+
+#include <span>
+#include <type_traits>
+
+static_assert(std::is_trivially_copyable_v<std::span<int>>);
+static_assert(std::is_trivially_copyable_v<std::span<int, 3>>);
diff --git a/libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp b/libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp
new file mode 100644
index 0000000000000..934ddbd2a9d69
--- /dev/null
+++ b/libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// P2251 was voted into C++23, but is supported even in C++17 mode by all vendors.
+
+// <string_view>
+
+#include <string_view>
+#include <type_traits>
+
+static_assert(std::is_trivially_copyable<std::basic_string_view<char> >::value, "");
+static_assert(std::is_trivially_copyable<std::basic_string_view<wchar_t> >::value, "");
+#ifndef _LIBCPP_HAS_NO_CHAR8_T
+static_assert(std::is_trivially_copyable<std::basic_string_view<char8_t> >::value, "");
+#endif
+static_assert(std::is_trivially_copyable<std::basic_string_view<char16_t> >::value, "");
+static_assert(std::is_trivially_copyable<std::basic_string_view<char32_t> >::value, "");
More information about the libcxx-commits
mailing list