[PATCH] D56997: Fix implementation of P0966 - string::reserve Should Not Shrink

Andrew Luo via Phabricator reviews at reviews.llvm.org
Wed Jan 23 10:29:04 PST 2019


andrewluo marked an inline comment as done.
andrewluo added inline comments.


================
Comment at: include/string:3144
+    size_type __cap = capacity();
+    if (__res_arg <= __cap)
+        return;
----------------
jwakely wrote:
> EricWF wrote:
> > After some more thinking, I think it's best we leave the old behavior as-is. All of the existing standard libraries seem to honor the shrink request prior to C++20, and that provides mostly consistent behavior to users. For consistency alone I think it's probably better not to backport this extension.
> For libstdc++ I think we have no real choice but to change it for all dialects. Our `std::string::reserve(size_type)` is exported from the shared library, so users will always get whatever behaviour the library exports, irrespective of their `-std` options. So we'll be changing `reserve(size_type)` to never shrink, unconditionally. So the consistency argument is lost.
Is it not possible to do the same as here in libstdc++:

Old version of reserve(size_type) is instantiated in the library (thus old code will still receive the old behavior) while marking the function inline for C++2a and forward (thus newer code will see the newer behavior)?


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

https://reviews.llvm.org/D56997





More information about the libcxx-commits mailing list