This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Verify span and string_view are trivially copyable
ClosedPublic

Authored by jloser on Oct 5 2021, 4:59 PM.

Details

Summary

Implement P2251 which requires span and basic_string_view to be
trivially copyable. They already are - this just adds tests to bind that
behavior.

Diff Detail

Event Timeline

jloser requested review of this revision.Oct 5 2021, 4:59 PM
jloser created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 4:59 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
jloser updated this revision to Diff 377393.Oct 5 2021, 5:00 PM

Explicitly include <type_traits> in tests

Quuxplusone requested changes to this revision.Oct 5 2021, 6:10 PM
Quuxplusone added inline comments.
libcxx/test/std/containers/views/trivially_copyable.compile.pass.cpp
19–24

(1) s/Trival/Trivial/g
(2) I don't think lines 18–23 are needed at all. We can trust that span doesn't do anything stupidly depending on the type-the-pointer-points-to.

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.
...Actually, it looks like libc++ supports string_view as an extension all the way back to C++03? is that true? So you'll want to use static_assert(std::is_trivially_copyable<...>::value, ""); below.

This revision now requires changes to proceed.Oct 5 2021, 6:10 PM
jloser updated this revision to Diff 377533.Oct 6 2021, 7:05 AM
jloser marked 2 inline comments as done.
jloser edited the summary of this revision. (Show Details)

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.

jloser added inline comments.Oct 6 2021, 10:30 AM
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.

ldionne requested changes to this revision.Oct 6 2021, 10:46 AM

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.

This revision now requires changes to proceed.Oct 6 2021, 10:46 AM

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.

@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.

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.

@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.

I just saw that! Thanks :)

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?
I think we should just be simple and aggressive with both of these tests, and then if someone actually turns up a third-party library that fails these tests, then we can PR how to disable them.

jloser updated this revision to Diff 377618.Oct 6 2021, 11:26 AM

Address review feedback

jloser marked 3 inline comments as done.Oct 6 2021, 11:27 AM
jloser updated this revision to Diff 377843.Oct 7 2021, 7:31 AM

Guard against char8_t not existing

Quuxplusone added inline comments.Oct 7 2021, 7:56 AM
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp
21

#ifndef _LIBCPP_HAS_NO_CHAR8_T plz

FYI, gdb_pretty_printer_test.sh.cpp failures in CI should go away once you rebase.

Mordante accepted this revision as: Mordante.Oct 7 2021, 8:53 AM

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.

jloser updated this revision to Diff 377877.Oct 7 2021, 9:00 AM

Use _LIBCPP_HAS_NO_CHAR8_T

jloser marked 4 inline comments as done.Oct 7 2021, 9:01 AM
jloser added inline comments.
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.

jloser marked an inline comment as done.Oct 7 2021, 9:01 AM
Mordante added inline comments.Oct 7 2021, 9:15 AM
libcxx/test/std/strings/string.view/trivially_copyable.compile.pass.cpp
21

Of course this is the string_view not the span. In that case I think it would be slightly better to guard against C++20, but I probably will update when I continue with D110868.

jloser added inline comments.Oct 8 2021, 8:46 AM
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?

ldionne added inline comments.Oct 8 2021, 10:21 AM
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.

ldionne accepted this revision.Oct 8 2021, 10:24 AM

LGTM once you update on top of D111166!

jloser updated this revision to Diff 378353.Oct 8 2021, 2:04 PM

Rebase and mark P2251 complete in Cxx2bPapers.csv

If BuildKite is still happy, I'll land this as-is.

jloser updated this revision to Diff 378355.Oct 8 2021, 2:08 PM

Run the tests on all vendors for all relevant standards. Let's see if any fail.

jloser marked 3 inline comments as done.Oct 8 2021, 2:08 PM
jloser added inline comments.
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.

jloser marked an inline comment as done.Oct 8 2021, 5:06 PM

The string_view test passes on all vendors. CI is green. Everyone still OK if I land this as-is then?

Quuxplusone accepted this revision.Oct 11 2021, 10:11 AM
This revision is now accepted and ready to land.Oct 11 2021, 10:11 AM