Implement P2251 which requires span and basic_string_view to be
trivially copyable. They already are - this just adds tests to bind that
behavior.
Details
- Reviewers
ldionne • Quuxplusone Mordante - Group Reviewers
Restricted Project - Commits
- rG70d7bef1e8ef: [libc++] Verify span and string_view are trivially copyable
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp | ||
---|---|---|
19–24 | (1) s/Trival/Trivial/g | |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
10 | This surely needs some // UNSUPPORTED: c++03, c++11, c++14, but buildkite will tell you for sure. |
Address review feedback
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp | ||
---|---|---|
19–24 | Removed them - I agree it was a bit far. For example, I thought about adding an evil custom char traits class to use as a template in the other test for string_view, but I thought it was a bit overkill. | |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
10 | Seems to be the case that libc++ supports string_view all the way back to C++03 oddly enough. Just fixed up the static_asserts to play nicely with older modes. |
In general looks good, just want to discuss the supported versions of the tests before approving.
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp | ||
---|---|---|
9 | A bit pedantic, but this is only required in C++23 not in C++20. Can you add a comment. (P2251 was not retroactively applied.) | |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
10 | libc++ originally "back-ported" several features to older standards. This gives us occasionally additional maintenance work. Nowadays we no longer back-port features. | |
10 | I wonder whether we should disable the test on older versions. This test will fail on MSVC STL in C++11 mode. Looking at cppreference.com I expect other implementations to be trivially copyable from the start. |
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp | ||
---|---|---|
9 | I can add a comment about it just working or mark it as UNSUPPORTED: c++20. Thanks for pointing out it doesn't retroactively apply to other standards modes. I don't feel strongly. @ldionne @Quuxplusone - do either of you have strong opinions? | |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
10 | I'd be OK marking this test as unsupported for all standards except C++23. |
We need to mark this paper as implemented in the status page. The Status pages haven't been updated for yesterday's meeting yet - let me do that now and then you can rebase on top.
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp | ||
---|---|---|
9 | I would do // UNSUPPORTED: c++03, c++11, c++14, c++17 // P2251 is supported by libc++ even in C++20 mode. // UNSUPPORTED: !stdlib=libc++ && c++20 | |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
9 | Can you add a comment explaining what this test is testing? Include a link to P2251. | |
10 | Here's what I suggest: // P2251 was voted into C++23, but libc++ guarantees triviality in all Standard modes, // so we enable the test in all Standard modes for libc++. // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14 || c++17 || c++20) Not the prettiest UNSUPPORTED annotation I've seen, but it does the job. |
@ldionne note https://reviews.llvm.org/D111166 is in flight. Let's have that land first and then I'll rebase with it and mark P2251 as complete in this PR.
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
10 | If we really care about !stdlib=libc++ cases that hypothetically might not have backported this fix, then shouldn't we also start caring about !stdlib=libc++ cases that don't support string_view in C++11 or C++14 at all? |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
21 | #ifndef _LIBCPP_HAS_NO_CHAR8_T plz |
LGTM modulo my last comment.
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
21 | Actually I think we can remove the #ifdef since we only support compilers providing char8_t. In D110868 I've started to make the support unconditional, but that was put on hold due to the Buildkite issues. (For now I'll wait until the @ldionne's wchar_t changes have landed.) If you want to add an #ifdef please use @Quuxplusone's suggestion. |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
21 | The issue is that clang only supports char8_t itself in C++20 or later, but this test is run in C++03 or later, so the #ifdef is needed. Switched to using #ifndef _LIBCPP_HAS_NO_CHAR8_T. |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
10 | I like the idea of this being more consistent with our other tests in libcxx/test of having these tests work for other standard library implementations. And if one of them fails, then we can mark it as XFAIL or UNSUPPORTED. Thoughts @ldionne? |
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
10 | Okay, I agree. So I guess we can just remove the UNSUPPORTED line entirely then. |
Rebase and mark P2251 complete in Cxx2bPapers.csv
If BuildKite is still happy, I'll land this as-is.
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp | ||
---|---|---|
10 | Yep, running these tests with all vendors now. Let's see if any fail and go from there now. Thanks @Quuxplusone. |
The string_view test passes on all vendors. CI is green. Everyone still OK if I land this as-is then?
A bit pedantic, but this is only required in C++23 not in C++20. Can you add a comment. (P2251 was not retroactively applied.)