[libcxx-commits] [libcxx] [libcxx] Allow string to use SSO in constant evaluation. (PR #66576)
James Y Knight via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 18 07:15:04 PDT 2023
jyknight wrote:
> Maybe we could add a warning for this case. I think that would address any portability concerns.
That's a great idea!
> I'm not quite sure the question here, `#warning` exists, but otherwise I'm not sure what type of warning you're looking for.
We want a warning if an object of a particular type (std::basic_string) is initialized at constant-evaluation-time, and then the resulting object escapes and is embedded into the resulting binary for use at runtime. The warning is justified for std::basic_string, because escaping the object to runtime is only possible (at least so far), when it doesn't point to any external memory allocations (and also it must not point to itself, when it's a local constinit variable) -- which are all internal implementation details. Whether a string meets these constraints is thus implementation-defined, and in practice varies based on platform and standard-lib implementation, and of course length of the string.
We could make a generic type attribute to diagnose this, or perhaps just hard-code it for std::basic_string.
https://github.com/llvm/llvm-project/pull/66576
More information about the libcxx-commits
mailing list