[libcxx-commits] [libcxx] [libc++] Replace __resize_default_init with resize_and_overwrite (PR #157121)
James Y Knight via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 22 09:15:01 PDT 2025
jyknight wrote:
Just FYI, we did resolve the issue by patching google's internal libc++ to expose resize_and_overwrite as `__google_nonstandard_backport_resize_and_overwrite` in pre-c++23 build modes.
ABSL has also been updated to expose a wrapper [absl::StringResizeAndOverwrite API](https://github.com/abseil/abseil-cpp/blob/HEAD/absl/strings/resize_and_overwrite.h) which adapts across the various possible implementations, and we're updating code to call that, instead of the now-deleted libc++-internal "default init" APIs.
While doing this, we discovered that the other C++ stdlibs actually all expose a `resize_and_overwrite` backport in pre-C++23 build modes. MSVC STL as [_Resize_and_overwrite](https://github.com/microsoft/STL/blob/249cb012aa0b6edf48bb970549e6d5dfbfa34859/stl/inc/xstring#L2312), and GNU libstdc++ as [__resize_and_overwrite](https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/include/bits/basic_string.h;h=8ae6569f50160137ed7d60b541b91539a45c18be;hb=HEAD#l1264). Notably, these were not exposed for the benefit of user code, but rather for each implementation's internal reasons -- MSVC in order to [optimize std::bitset::to_string](https://github.com/microsoft/STL/commit/5df783410648ee977c2f14602adf3de37adc65cf), and libstdc++ to optimize [std::format](https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=95c2b0cc9eaa5b9fbec34e8c5399c7d8f07f329b) and [std::to_string(integer-type)](https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=51ec07b116b802d845d762beddf8b98e8c0e32ab).
I won't ask that libc++ add a supported extension for a backported API...but if libc++ had internal code where it'd be useful to call `resize_and_overwrite` in the implementations of pre-C++23 functionality, and therefore happened to define a function `basic_string::__resize_and_overwrite` API to enable such internal calls, that might be a convenient happenstance for all parties. :)
https://github.com/llvm/llvm-project/pull/157121
More information about the libcxx-commits
mailing list