[libc++] Assert that lengths fit in difference_type
authorDavid Benjamin <davidben@google.com>
Sun, 19 Mar 2023 17:41:04 +0000 (18:41 +0100)
committerMark de Wever <koraq@xs4all.nl>
Sun, 19 Mar 2023 17:42:22 +0000 (18:42 +0100)
commit61363445d46d72e2a6c8a821f4146c985404840d
tree4d7689aaab0e9e4bb77d1201860943e121fbf9a0
parente657eb62559af2e1968ee77910db28d0bf2e3d01
[libc++] Assert that lengths fit in difference_type

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

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D145981
libcxx/include/string_view
libcxx/test/libcxx/strings/string.view/assert.ctor.length.pass.cpp [new file with mode: 0644]