This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Disallow dynamic -> static span conversions
AbandonedPublic

Authored by ldionne on Oct 28 2019, 11:15 AM.

Details

Summary

[libc++] Disallow dynamic -> static span conversions

This change disallows dynamic to static span conversions. This complies
with the standard, which lists the following constaint in
views.span#span.cons-20.1 [1]:

Extent == dynamic_extent || Extent == OtherExtent

Thus this should fail if Extent != dynamic_extent && Extent !=
OtherExtent, which is the case when trying to construct a static span
from a dynamic span.

[1] https://eel.is/c++draft/views.span#span.cons-20.1

Diff Detail

Event Timeline

jdoerrie created this revision.Oct 28 2019, 11:15 AM
jdoerrie updated this revision to Diff 226713.Oct 28 2019, 11:21 AM

Formatting

jdoerrie updated this revision to Diff 226714.Oct 28 2019, 11:23 AM

Full patch

Friendly Ping :)

+1

Thanks also for fixing the return statement of testConversionSpan() in span.pass.cpp

Thanks Jorg! Given that the status is still "Needs Review", I assume I also still need an LGTM from Marshall, Louis or Eric, right?

mclow.lists added inline comments.Nov 1 2019, 12:32 AM
libcxx/test/std/containers/views/span.cons/span.fail.cpp
78 ↗(On Diff #226714)

Ok. The comment here is wrong; this is testing dynamic -> static.

However, why are you removing these (failing) tests?

libcxx/test/std/containers/views/span.cons/span.pass.cpp
64–65

These cases (on the other hand) should be moved to a failure test.

80

Please line these up like the other ones were. Makes it easy to see copy-pasta errors:

return s1.data() == nullptr && s1.size() == 0 
    && s2.data() == nullptr && s2.size() == 0
    && s3.data() == nullptr && s3.size() == 0;
113

same comment as above re: alignment.

jdoerrie updated this revision to Diff 227605.Nov 3 2019, 3:53 AM
jdoerrie marked 4 inline comments as done.

Addressed Marshall's comments

libcxx/test/std/containers/views/span.cons/span.fail.cpp
78 ↗(On Diff #226714)

Considering that Extent == dynamic_extent || Extent == OtherExtent should be checked first I felt these particular tests distracted from the actual root cause of the error. I added now a new section that performs explicit Extent checks.

libcxx/test/std/containers/views/span.cons/span.pass.cpp
80

FWIW my formatting was performed by clang-format. Do you think it's worth wrapping this block in

// clang-format off
...
// clang-format on

so that this doesn't regress in the future?

Friendly Ping

miscco added a subscriber: miscco.Feb 16 2020, 10:12 AM

I believe this is superseded by the implementation of P1976R2 in D74577

Oh interesting! Yes, it looks like you are right.

ldionne commandeered this revision.May 14 2020, 6:45 AM
ldionne edited reviewers, added: jdoerrie; removed: ldionne.

I believe this is superseded by the implementation of P1976R2 in D74577

@miscco Can you please look at the tests in this patch and salvage any test you might have omitted from your own patch?

@jdoerrie I'm sorry there was some confusion and duplicate work, but thanks for your contribution nonetheless!

ldionne abandoned this revision.May 14 2020, 6:45 AM