[libcxx-commits] [PATCH] D110598: [libc++] Implement P0980R1 (constexpr std::string)

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 25 09:13:24 PDT 2022


philnik added inline comments.


================
Comment at: libcxx/include/string:1636-1638
+                return static_cast<size_type>(__min_cap);
+            else
+                return static_cast<size_type>(__min_cap) - 1;
----------------
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.


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