<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57760>57760</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Regression: clang-14: constexpr variable cannot be captured by lambda
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wanghan02
</td>
</tr>
</table>
<pre>
Code could be found below or on [godbolt](https://godbolt.org/z/qz97Gf1qo). clang 14 gives error message about constexpr variable 'n' cannot be implicitly captured in lambda. clang 14 compiles If n is const instead of constexpr. clang 14 also compiles if noexcept specifier of the inner lambda is removed. The code compiles with clang 13, gcc and VS.
```
#define TEST_CONSTEXPR constexpr
//#define TEST_CONSTEXPR const
#define TEST_NOEXCEPT(...) noexcept(__VA_ARGS__)
//#define TEST_NOEXCEPT
template<typename... T>
void ignore(T&&...) {}
void foo() {
auto TEST_CONSTEXPR n = 5;
auto x = [&]() {
ignore(
n, // error: variable 'n' cannot be implicitly captured in a lambda with no capture-default specified
[]() TEST_NOEXCEPT(noexcept(ignore())) {
ignore();
}
);
};
ignore(x);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVE1vozAQ_TXmYhXxTTlwSJO02ktbNdGqt8jAQLxybGpMmvTX70ACZJOqh0UmwZ7xzJv3xs5UcUznqgCaq1YUNANaqlZ2H0J9UqWpkpSED5UqMiUMCRfEu98aUzfEnxHvEcfZZCtd4ewL34-vJH4q3Q9FvMSmuWCyom5AK76HhoLWGHUHTcMqoCxTrcHcsjFwqDXdM81ZJoASL5b40pxJqUyHi-9qwXNuxBEXa9NqKCiXVLBdVrCLNLna1Vxgpl8llZQ3p-joiilYQVU5pbvYxUSjpq0ctyo45FAb2tSQ85KD7raaLQKREienvF18DTu1h8Km621HY8_lOc4nN9shh0-8Oa3ynDKk9_fKJs6COLPzb-Scx2nq-QWUXAJdL1frzfzlebVevr--TcgHv8d-_OT9bcTnl-X7fPm6RjFt20aZxnJxZbP5PdvM3p5Wmw1afsg0RrmoxADKxAwQf26ONUi2A8xA18Rfnhz2iqNulVQaMBciiHCcQZD4gcSLy3C9d6mwk-4Hh36d4sNao65Lxmb1FzQk_sNllNH70Juxn7u0fS_fRO2eEd6_y90jOxVPbJxaGc_Bf3QtG_qn7xCpBuMd8staMXVdcQuhgz9iv5bzQsepClSxH7eV3laMjv43TqMu48KVY-cwsZ5MhjH04XLLpPPQ-hakbhT5XugGYWgVqV8kfsIsg9xB-gaVxiuDK9nx3Z-oOzfov2_vjon9kfLseCbcarVIry4wlKDNbDy0OBFiP_zd1Vr9gRypfORN00KDH2EcI9Jt6gWQgVsmkRtGLMjKCNh9xDwHWBYHoRtaguEN2qQnrSyeeo7nOYmLxbmxH9rgexD4rIgjFgZJUZDAgR3jwu4Sd1eppdMeQ9ZWDRoFb0wzGRlSUUmAIT4291bp9BNp2TLpeFYPOO3R_gVMZL-r">