[libcxx-commits] [libcxx] [libc++] Fix throwing away smaller allocations in string::shrink_to_fit (PR #115659)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 11 06:49:25 PST 2024
================
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <string>
+
+// void shrink_to_fit(); // constexpr since C++20
+
+// Make sure we use an allocation returned by allocate_at_least if it is smaller than the current allocation
+// even if it contains more bytes than we requested
----------------
philnik777 wrote:
Implementations aren't required to do anything when `shrink_to_fit()` is called. `void shrink_to_fit() {}` is a valid implementation: http://eel.is/c++draft/basic.string#string.capacity-16
https://github.com/llvm/llvm-project/pull/115659
More information about the libcxx-commits
mailing list