[libcxx-commits] [PATCH] D117332: [libc++] Make sure basic_string::reserve never shrinks in all standard modes

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 20 15:57:02 PST 2022


ldionne added a comment.

In D117332#3252167 <https://reviews.llvm.org/D117332#3252167>, @Quuxplusone wrote:

> Everything here makes sense //except// the decision to make `s.reserve()` nonequivalent to `s.shrink_to_fit()`. I don't see any ABI issue with that, so that part of the patch is orthogonal to the rest — and it seems to be altering behavior that is both useful and cppreference-documented. I suggest doing everything else you're doing, but //not// that specific one-line diff, because I don't see its upside.

The rationale is that `reserve()` is supposed to be the same as `reserve(0)` -- actually in C++03 `reserve` is specified as a single overload with a default argument: `reserve(int = 0)`. If I make `reserve()` a synonym for `shrink_to_fit()`, it won't be equivalent to `reserve(0)` anymore. I think we have to pick our poison here: either `reserve()` and `reserve(0)` are inconsistent, or `reserve()` and `reserve(0)` are consistent but `reserve()` is inconsistent with what the Standard suggests.

Thoughts? Does that change your opinion?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117332/new/

https://reviews.llvm.org/D117332



More information about the libcxx-commits mailing list