[libcxx-commits] [PATCH] D114395: [libc++] Fix the return value of max_size()
Marshall Clow via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 29 14:07:42 PST 2021
mclow.lists added a comment.
The definition of `max_size()` is the maximum number of elements that a `string_view` can hold.
(Actual definition: Returns: The largest possible number of char-like objects that can be referred to by a `basic_string_view`.)
Also, `numeric_limits<size_t>::max()` is the maximum size (in bytes) of any data structure.
My argument is that those two imply that `sv.max_size() * sizeof(sv::value_type)` (pardon the fak-ey code) should:
- Not overflow.
- Be no larger than `numeric_limits<size_t>::max()`
Interestingly enough:
- libstdc++ returns: `(numeric_limits<size_t>::max() - epsilon)/sizeof(Elem)`
- MSVC returns: `min(numeric_limits<ptrdiff_t>::max(), numeric_limits<size_t>::max() - eps)/sizeof(Elem))`
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114395/new/
https://reviews.llvm.org/D114395
More information about the libcxx-commits
mailing list