[libcxx-commits] [libcxx] [libc++] Fix `basic_string::shrink_to_fit` for constant evaluation (PR #142712)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 4 02:41:51 PDT 2025


frederick-vs-ja wrote:

> > Currently, when the string shrink into the SSO buffer, the lifetime of the buffer hasn't begun before copying characters into it, so the subsequent copy operation raises UB and thus causes constant evaluation failure.
> 
> This is incorrect. It's not UB, since we know that `CharT` is an implicit lifetime type, so we start the lifetime when copying the elements.
> 
> LGTM with updated commit message.

Yeah. Changed to the following. Is it OK enough?
> Currently, when the string shrink into the SSO buffer, the `__rep_.__s` member isn't activated before the `traits_type::copy` call
yet, so the `__get_short_pointer` reads an inactive member and then causes constant evaluation failure.

https://github.com/llvm/llvm-project/pull/142712


More information about the libcxx-commits mailing list