[libcxx-commits] [libcxx] [libc++] Fix `basic_string::shrink_to_fit` for constant evaluation (PR #142712)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 4 03:29:57 PDT 2025
philnik777 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.
Does the error occur in `__get_short_pointer`? IIRC that should only return a pointer to an inactive member, not actually read it. That might not be allowed during constant evaluation either, I can't remember.
https://github.com/llvm/llvm-project/pull/142712
More information about the libcxx-commits
mailing list