[libcxx-commits] [PATCH] D114395: [libc++] Fix the return value of max_size()

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 6 10:52:52 PST 2021


ldionne accepted this revision as: libc++.
ldionne added a comment.

In D114395#3159527 <https://reviews.llvm.org/D114395#3159527>, @mclow.lists wrote:

> 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()`

This is what sways me. I think we all agree that `max_size()` is kind of a ridiculous method. However, the current definition is more wrong than the one proposed in this patch based on the above criteria, which I think is good. Well, I don't really care that much, but I think it's no wronger than what we are doing anyways.

Accepting as libc++ based on Marshall's review.


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