<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69561>69561</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Captured std::string_view not usable in a constexpr context
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pkasting
</td>
</tr>
</table>
<pre>
The following code compiles on gcc and msvc trunk in C++20 mode, but fails in Clang:
```
#include <string_view>
template <typename T>
constexpr void l(T t) {
static_assert(t() == "test");
}
void bar() {
// Works in Clang/gcc/msvc
constexpr std::string_view kTest = "test";
l([=]() -> std::string_view { return "test"; });
l([=]() -> std::string_view {
constexpr std::string_view kTest = "test";
return kTest;
});
// Fails in Clang, works in gcc/msvc
l([=]() -> std::string_view {
return kTest;
});
}
```
Online repro: https://godbolt.org/z/3x6nzva7b
It seems like this should compile. A constexpr std::string_view should still be inspectable in a constexpr context even after being captured.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE2PozgQ_TXFpdQRKScBDhySMEh72ktLexwZqBBvjI3sIt0zv34Fk_Ske0e7q20p4UN-9fzeq8I6RtM75hK2B9hWiZ7k7EM5XnQU4_qk8d238vnMePLW-hfjemx9x9j6YTSWI3qHfduidh0O8dqihMld0Dg8Ah2ADpTi4DsGOmIzCZ60sXFZttr1oPaQVpDuYZfefj9eSRnX2qljBHWMEozrv14Nv4D6ckMsV-FhtFoWlHwb2emB8fkN1HoXhV_HgFdvOrRA-TMKUIGQHX5AMIoW037VMXIQoHz-LwhVgaoQiISjABFQAepWBVn1KGNhb3S4l76RI1ANVOMfPlweXFPdty1QPQd2R_7UGqWbc1H7B994eeYo-EGRettntjZ3UFWwrW4ynkB9-TUZZAcMLFNw79lw9vVg83_w3gs_awjvAhfcw8IHiR-Crt-PFx3x5R793yP_hLn_KO5tTN6P9-_OGscYeAwe1B7PImOcd1xM9L5rvJWVD_OkfAeq1evOfb_qrHn0_JtgZB4iWnNhlLOJGM9-st3921zh_t-acCuIYqzFhtG4OHIrurHzM-qH-tY74VdBvrJDfRIO2PByHOhRpsDdKulK1RWq0AmX612R7QpSG5Wcy_UmbVN1ooYUFZSd1rvTltO00ZSn2bbgxJSUklqn6yLdronUqsnzzS7jPG-oY5VvYJPyoI1dWXsd5mASE-PE5a7Y7taJ1Q3buJxgRI5fcFmc52lbJaGca56aqY-wSa2JEn-yiBHL5fHm4NcZOS84xX-IJJmCLT-00Mh5alatH4Dqebfb7WkM_k9uBaheNEagevHwVwAAAP__b9aohQ">