<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61278>61278</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang rejects-valid(?) on lambda template with requires-clause following template-parameter-list consisting of a variable template
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++20,
clang:frontend,
rejects-valid,
concepts
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rymiel
</td>
</tr>
</table>
<pre>
Compiler Explorer demonstration: https://godbolt.org/z/x8oT5Y9bz
According [to the C++ grammar](https://eel.is/c++draft/expr.prim.lambda.general#nt:lambda-expression), a *lambda-expression* can contain a *requires-clause* after its *template-parameter-list* (added in [p0857r0](https://wg21.link/p0857r0))
However, when said *requires-clause* consists of a single bool variable template, as is common with std type trait `_v` helpers, clang seems to get confused and fails to properly parse the lambda, such as the following:
```c++
[&]<typename Callable>
requires foo_v<Callable>
(Callable&& callable)
{
static_cast<void>(callable);
};
```
Resulting in odd errors such as:
```
error: 'Callable' does not refer to a value
(Callable&& callable)
^
note: declared here
[&]<typename Callable>
^
error: use of undeclared identifier 'callable'
(Callable&& callable)
^
```
Note that for other similar cases, such as a type-trait-esque static member constant, or a concept, this seems to work fine, as demonstrated in the Compiler Explorer link above.
Also note that this example works for GCC, also demonstrated on Compiler Explorer.
Related to https://github.com/llvm/llvm-project/issues/46720
If I had to guess, it probably has to do with the fact that, syntactically, this construct is very weird due to the parentheses immediately following the requires clause, and is possibly being parsed as a cast or something. I also am not sure if this is a bug at all, since I'm not well versed in standardese, and the grammar is only informative, to my knowledge.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVk9z47YP_TT0BWOPTEWWffDBcda_Xy49dHrpaQcSIYlditSSlB3vp--A8r9s0pltM5kkBkHg4RF4CIagW0u0FcWzKF5mOMbO-a0_95rMrHLqvN27ftCGPHx5G4zz5EFR72yIHqN2VuQ76GIcgsh3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