This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Assert that lengths fit in difference_type
ClosedPublic

Authored by davidben on Mar 13 2023, 12:45 PM.

Details

Reviewers
rsmith
Mordante
Group Reviewers
Restricted Project
Commits
rG61363445d46d: [libc++] Assert that lengths fit in difference_type
Summary

This can help flag accidentally passing in negative values into the string_view constructor. This aligns with a similar check in absl::string_view.

Fixes https://github.com/llvm/llvm-project/issues/61100

Diff Detail

Event Timeline

davidben created this revision.Mar 13 2023, 12:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 12:45 PM
davidben requested review of this revision.Mar 13 2023, 12:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 12:45 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

(This is my first time contributing here or using this tool, so let me know if I got something wrong!)

davidben edited the summary of this revision. (Show Details)Mar 13 2023, 12:47 PM
alex added a subscriber: alex.Mar 13 2023, 12:54 PM

Thanks for your contribution, a few comments.

libcxx/test/libcxx/strings/string.view/assert.ctor.length.pass.cpp
11–13

Why is this not supported in these language versions? We have enabled string_view in older language versions.

16

Please add the function's synopsis here, best look for other tests for examples.

davidben updated this revision to Diff 505639.Mar 15 2023, 3:22 PM

Updates the test per review.

davidben added inline comments.Mar 15 2023, 3:22 PM
libcxx/test/libcxx/strings/string.view/assert.ctor.length.pass.cpp
11–13

I just copied that from assert.ctor.pointer.pass.cpp. :-) Removed.

16

Something like this?

davidben added inline comments.Mar 15 2023, 8:07 PM
libcxx/test/libcxx/strings/string.view/assert.ctor.length.pass.cpp
11–13

Looks like that didn't work because the assertion is only allowed in constexpr starting C++14. I'll make this match the other assert and disable the test in C++11.

davidben updated this revision to Diff 505690.Mar 15 2023, 8:16 PM

Hopefully fix C++11 test failures.

Mordante accepted this revision.Mar 16 2023, 9:48 AM

LGTM, but can you reupload this revision to see that it passes the Windows CI, these errors look odd so I like to have a rerun. It seems the exception issue is unrelated.

Can you provide "your name" <your@e.mail> then we can commit on your behalf when the CI is happy.

libcxx/test/libcxx/strings/string.view/assert.ctor.length.pass.cpp
11–13

Oke sounds good.

16

Yes thanks!

This revision is now accepted and ready to land.Mar 16 2023, 9:48 AM
davidben updated this revision to Diff 505928.Mar 16 2023, 2:26 PM

Reuploading

LGTM, but can you reupload this revision to see that it passes the Windows CI, these errors look odd so I like to have a rerun. It seems the exception issue is unrelated.

Done.

Can you provide "your name" <your@e.mail> then we can commit on your behalf when the CI is happy.

"David Benjamin" <davidben@google.com>

This revision was landed with ongoing or failed builds.Mar 19 2023, 10:42 AM
This revision was automatically updated to reflect the committed changes.

Can you provide "your name" <your@e.mail> then we can commit on your behalf when the CI is happy.

"David Benjamin" <davidben@google.com>

Thanks I just committed this patch on your behalf, feel free to close the bug report.