-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::basic_string wrong capacity calculation when sizeof(CharT)=3, 5, or >8 #51158
Comments
Stable ABI should be
of course |
The first two points don't seem like bugs to me. It's totally normal and expected for The third point, "memory leak detected by ASan," seems like a bug, but I wasn't able to reproduce it from your description. Could you post a minimal compilable example? Include the complete compiler command line (e.g. I tried to reproduce by doing this:
However, this test passes just fine — no errors detected at all. #30802 is probably related. |
@Quuxplusone, the test was attached to the original Bugzilla issue. Here is even more minimal reproducer:
It fails as follows:
|
I believe, that in order to reproduce the bug, you have to switch between SSO-string and allocating one. |
Ah, now I see it!
Fails for
|
I have tried to debug this by myself, but the code is too hard to understand without comments, so I have ended with adding So far, this worked just fine as 32 bits is enough for everyone. |
Extended Description
An attempt to compile
std::basic_string
with various weird character types would lead to a multiple issues.So far I have found the following:
-fsized-deallocation
is enabled and stable ABI is used (i. e._LIBCPP_ABI_VERSION == 2
):This is caused by incorrect alignment in
__recommend()
and attempt to allocate odd number of characters. Stringcapacity()
must be even as odd bit will be overwritten by__long_mask
.Though C++ standard does not limit
sizeof(CharT)
, I suggeststatic_assert(sizeof(CharT) <= 4)
to be added into libc++.Though this could break existing codebases, I consider the break fast to be the better option.
I do not think SSO is anyway helpful whenever
sizeof(CharT) >= 8
. Maybe we should ensure thatstd::basic_string
is always long is such cases.The text was updated successfully, but these errors were encountered: