<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75755>75755</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
libc++: constexpr std::string does not work (clang 17)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
q66
</td>
</tr>
</table>
<pre>
The following code:
```
#include <string>
constexpr std::string foo{"XX"};
int main() {
}
```
should compile, but instead it fails with:
```
test.cc:3:23: error: constexpr variable 'foo' must be initialized by a constant expression
3 | constexpr std::string foo{"XX"};
| ^~~~~~~~~
test.cc:3:23: note: pointer to subobject of heap-allocated object is not a constant expression
/usr/bin/../include/c++/v1/__memory/allocator.h:112:38: note: heap allocation performed here
112 | return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
| ^
1 error generated.
```
I haven't been able to find anything about this being broken, and available resources list the functionality as available since 15.
This is a musl/libc++/compiler-rt environment, on x86_64 architecture, but probably should not matter. The libc++ has hardened mode on.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE2T4yYQ_TX40jUqqbEs-6CDx7Oqyn0Oe3MhaFlkESiAPOs95Len2vZknNRkDqEobEE_-us9VEr25IlaUT-L-mWlljyG2P6x2az6YC7t60gwBOfCm_Un0MGQkHtRvojyfd2U93n7RGm9doshEPKQcrT-JOS3R4QOPmX6OUdI2fBtcn-zgyEE0TwLxO_fBaJoXoR8fkRan2FS1gvcCtwB295Om5fPg7muaQyLM6DDNFtHAg_QLxksB6EM2AyDsi7Bm83j17llSrnQWsi9FHKPvADFGCL_-cjqrKJVvSMQ2HBG2MC0pAw9gfU2W-XsLzLQX0DdUMpnYCSlZIO_-QIAkCCaA_yfcsF1MFrU3_68j_9OwofMbYU5WJ8pQg6Qlj70v5POEAYYSc1PyrmgVSYD9wObGPhVEgK7JUWBXc8964pCYHdnh8BOC3y-zu5cC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