<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95735>95735</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang]: clang rejects valid codes when it trying capturing something never occuring in lambda body
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RungeCC
</td>
</tr>
</table>
<pre>
```c+++
struct A {
void operator()(int) {}
};
inline constexpr struct {
constexpr auto operator()(A fn) const
{
return [f{static_cast<A>(fn)}](auto &&tpl)
noexcept(noexcept(&f))
{ return true; };
}
} error;
inline constexpr struct {
constexpr auto operator()(A fn) const
{
return [f{static_cast<A>(fn)}](auto &&tpl)
// noexcept(noexcept(&f))
{ return true; };
}
} no_error;
int main() {
(void)error( A{} )(1);
(void)no_error( A{} )(1);
}
```
- clang trunk with flag `c++26`
- https://godbolt.org/z/hMacPx4a6
- see `no_error` and `error` function object, if I delete the `noexcept` clause then everything is OK.
- clang tells me to capture `fn`, which is weird (since `fn` is never used in function body), but if I do so, clang accepts it.
- if I change `f` inside the `noexcept` to `fn`, then again, everything would be fine.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVcuuszYQfpphM0pETLgtWOTSSFVVteoL_DLGgFvHjuwhOadPX9mQhLZH3XXxRygQz-W7eHC492owUjaQHyE_J3yi0brmt8kM8nRKWtt9NlCk8yWAHZcrPUN6mL89uUkQHhDKZR3xblWH9iYdJ-uAVcBqYJUyBKyOeeV5aVGeIVvKlNHKSBTWeJIfN4dL53ffd4hPZP8NcMDeBISY9-SyooXoJE3OIOTHHsqjJ05KfBPcE2SnA2Q_AKtii8ArPwOrIhCwAlhBNx3pv5qFj7HyQ8gbAatWj8CKPlKql2woj09scpOE7Ihr6YhrR1A6Z90r-B27A-wC7PL_mGTst698-rtnhFeuzGzBSiuwKowosHpuwSo8zGOJs1e7cFsBv_JfqP9d8p7u-eH5Cq2jGxSamyFoNX_gQ9GIveYDvt80VrxKNjgS3Txkh9nTwXat1bS1bgB2-RPYZfyZi18_9rx4kt6glzJ0e3EuUuSmC0uv3_1kBClr0La_S0HATqh6_BE7qSVJpHHpsOxakQbSk48Rg_Iu3SeNygyoPP7y0_aNvWiTWnu8SiSLgt9ocrFfb4IwdsLHqMQYah9SuS747JUR75wQMgEFJy87VOZNOJxN0fkTthMtrC16G1ZmdC4CaY-KVsRiohi5GWaYiGK86r5UG-Z7xTeq5kOcqdNa_sNOusNWYq-MXNCSrsm6Oqt5IptduavyuqhYloxNlrGeM5FzUXdVmXddX7f7fZ9VfV_tRZsnqmEp26fFrkz3acqybSV2VS94LQrec9lWsE_llSu91fp-DUOQKO8n2dR5meWJ5q3UPp7pjEUrgLFwvLsm5G_aafCwT7Xy5N8dSJGOfwSnWJGfITssRjoZhsPjnWvVobCd9PgIVihCcp_BgHl3w5O3VzmbMu-cFWIOKIOaX9uOx71LJqebfwy1onFqt8JegV0Cr-W2uTk7T-clyvTALrPSe8P-CgAA__-dPvuA">