<story><title>Just how constexpr is C++20’s std:string?</title><url>https://quuxplusone.github.io/blog/2023/09/08/constexpr-string-firewall/</url></story><parent_chain></parent_chain><comment><author>cmovq</author><text>&amp;gt; libstdc++ rejects the following code (Godbolt [1]). (Microsoft accepts, but I think that might be an MSVC bug.)&lt;p&gt;This is not a bug in MSVC, rather it is due to MSVC implementing std::string SSO differently than gcc or clang. Instead of initializing `data` as pointing to the internal buffer for small strings, MSVC uses the string&amp;#x27;s capacity to determine whether to access `data` or the internal storage [2].&lt;p&gt;Hence this code compiles, as it&amp;#x27;s not initializing the string using a stack address. [3]&lt;p&gt;[1]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;godbolt.org&amp;#x2F;z&amp;#x2F;1ErrKjdbq&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;godbolt.org&amp;#x2F;z&amp;#x2F;1ErrKjdbq&lt;/a&gt;&lt;p&gt;[2]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;devblogs.microsoft.com&amp;#x2F;oldnewthing&amp;#x2F;20230803-00&amp;#x2F;?p=108532&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;devblogs.microsoft.com&amp;#x2F;oldnewthing&amp;#x2F;20230803-00&amp;#x2F;?p=10...&lt;/a&gt;&lt;p&gt;[3]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;godbolt.org&amp;#x2F;z&amp;#x2F;1MaxdGfvj&quot; rel=&quot;nofollow noreferrer&quot;&gt;https:&amp;#x2F;&amp;#x2F;godbolt.org&amp;#x2F;z&amp;#x2F;1MaxdGfvj&lt;/a&gt;</text></comment>
<story><title>Just how constexpr is C++20’s std:string?</title><url>https://quuxplusone.github.io/blog/2023/09/08/constexpr-string-firewall/</url></story><parent_chain></parent_chain><comment><author>kccqzy</author><text>I find that there&amp;#x27;s no use case for a constexpr std::string. Maybe I&amp;#x27;m just not imaginative enough. If I want a string literal constant, I use string_view which can be constexpr. If somehow I need an actual std::string object, I use a regular const not constexpr. What would be a use case that prompts the author to explore using constexpr with std::string?</text></comment>