<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63686>63686</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`std::bit_cast` of a string literal is not a constant expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Eisenwave
</td>
</tr>
</table>
<pre>
The following code should succeed, but fails to compile:
```cpp
#include <bit>
// error: constexpr variable 'x' must be initialized by a constant expression
constexpr auto x = std::bit_cast<int>("xyz");
```
```
error: constexpr variable 'x' must be initialized by a constant expression
constexpr auto x = std::bit_cast<int>("xyz");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
note: subexpression not valid in a constant expression
return __builtin_bit_cast(_To, __from);
^
note: in call to 'bit_cast("xyz")'
constexpr auto x = std::bit_cast<int>("xyz");
^
1 error generated.
```
Putting the string literal into a `char[4]` first solves the problem, but it should work either way.
*See [Compiler Explorer](https://godbolt.org/z/dbqo7o8nc)*
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVMuu4zYM_Rp6Q0zgSLHju_Aiz3WBzj6QLDpWq0iuROdxF_32wnamt5m57a7ACAb8IEgeHp5jlZI9e6Iaii0U-0wN3IVYH2wif1NXynQwj_prR9gG58LN-jM2wRCmLgzOYBqahsiA2KEeGFtlXUIO2IRLbx2B3EC-h3wDZT5fTd8_vwhpfeMGQwhypy2DPDwjz_gRxBEpxhBBbrAJPjHd-4hXFa3SjhDE-g5ijZchMWpC6y1b5ew7GdQPVHOO8oxjHqVkg5-LfxRTAwe8I8g9JjYjXrnRlk-NSgxyZ_2ES1QgxP3xDkKAeAO5_W6qT19_auj4eqA44J__duYMH3jcJ6ZBf2BCHxivylmD1v8X7LlNJB6ix9NJD9ax9ae_8Yrq9DWMMjqd2hguL1ChOLxCsB4b5dwoNBDrf9R4GVWs_0_GnqzNseWsUzyTp6iYzOJTRfwyMI8O4o4wcRwfnWWKyqH1HFDh6JBORSi2Kyj2UObY2pgYU3BXSlNiH4N2dPlmOcvfvHgL8Xckyx1FvKnH4tVNm1-JEIrtbnZmxMO9dyFSHPuIqmPu08jIZLtzMDo4XoR4BnF8B3E0-o-wDpVvJmY3mamleZNvKqN6WVZVUeb5cpl1ddMKIaUoWiPfZLXMdbUqSFJbSKGIzCqztciFzNd5sRSiLJaLlcxLSaWs1o2pSkmwyumirFs4d72MCDKb0kB1KcuqzJzS5NL0uxLC0w2n4LiqYp_Fesz5oodzglXubOL0UYUtO6qhzH9cfZljaFH9sJM0yftTVWdDdPV3pFnuBr1oRvUex7bP25c-ht-oYRDHCWwCcZyG-SsAAP__m5K2bA">