[libcxx-commits] [PATCH] D110598: [libc++] Implement P0980R1 (constexpr std::string)
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Apr 26 12:51:47 PDT 2022
ldionne accepted this revision.
ldionne added a comment.
Please rebase onto `main` to get a clean CI run, and ship it. Thanks!
================
Comment at: libcxx/include/string:1636-1638
+ return static_cast<size_type>(__min_cap);
+ else
+ return static_cast<size_type>(__min_cap) - 1;
----------------
philnik wrote:
> ldionne wrote:
> > Can you explain this?
> During runtime we never actually allocate `__min_cap` bytes, so it's OK that we return an even number in this case. It only exists for checking if the string fits in SSO or is in SSO mode AFAICT. (This should probably be changed at some point) During constant evaluation we have to return an odd number to make the allocation size even, otherwise we save garbage in the capacity member. That's why the other way to fix the bug was saving the actual capacity.
Ok. As discussed offline, let's land this as-is, but let's also make a follow-up patch that tries to fix places that assume `__min_cap - 1` is returned when the string fits in the SSO, so we can remove this `if` and always return `static_cast<size_type>(__min_cap);`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110598/new/
https://reviews.llvm.org/D110598
More information about the libcxx-commits
mailing list