[all-commits] [llvm/llvm-project] b96441: [libcxx] Allow string to use SSO in constant evalu...
James Y Knight via All-commits
all-commits at lists.llvm.org
Tue Oct 10 11:32:02 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b964419ec295c8971c0d3c93608ad30ac8fe40fb
https://github.com/llvm/llvm-project/commit/b964419ec295c8971c0d3c93608ad30ac8fe40fb
Author: James Y Knight <jyknight at google.com>
Date: 2023-10-10 (Tue, 10 Oct 2023)
Changed paths:
M libcxx/docs/UsingLibcxx.rst
M libcxx/include/string
A libcxx/test/libcxx/strings/basic.string/string.cons/constinit_sso_string.compile.pass.cpp
M libcxx/test/std/utilities/template.bitset/bitset.members/to_string.pass.cpp
Log Message:
-----------
[libcxx] Allow string to use SSO in constant evaluation. (#66576)
Previously, libcxx forced all strings created during constant evaluation
to point to allocated memory. That was done due to implementation
difficultites, but it turns out not to be necessary. This patch permits
the use of SSO strings during constant evaluation, and also simplifies
the implementation.
This does have a downside in terms of enabling users to accidentally
write non-portable code, however, which I've documented in
UsingLibcxx.rst.
In particular, whether `constinit std::string x = "...";` will
successfully compile now depends on whether the string is smaller than
the SSO capacity -- in libc++, up to 22 bytes on 64-bit platforms, and
up to 10 bytes on 32-bit platforms. By comparison, libstdc++ and MSVC
have an SSO capacity of 15 bytes, except that in libstdc++,
constant-initialized strings cannot be used as function-locals because
the object contains a pointer to itself.
Closes #68434
More information about the All-commits
mailing list