<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84961>84961</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Code using a lambda to capture a reference to a function rejected with `could not match (null template argument) against (null template argument)`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
abbeyj
</td>
</tr>
</table>
<pre>
The following code is accepted by other compilers but rejected by clang. The error message is a bit weird.
```C++
template<typename T>
void g(const T& t) {
}
template<typename T>
void f(const T& t) {
[t] { g(t); };
}
void h() {
}
int main() {
f(h);
}
```
Output:
```
<source>:7:9: error: no matching function for call to 'g'
7 | [t] { g(t); };
| ^
<source>:7:7: note: while substituting into a lambda expression here
7 | [t] { g(t); };
| ^
<source>:14:3: note: in instantiation of function template specialization 'f<void ()>' requested here
14 | f(h);
| ^
<source>:2:6: note: candidate template ignored: could not match (null template argument) against (null template argument)
2 | void g(const T& t) {
| ^
```
Changing the call `g(t)` to be either `g<T>(t)` or `g<void()>(t)` changes the error message to:
```
note: candidate function template not viable: 1st argument ('void (const()') would lose const qualifier
```
Note that the type mentioned here (`void (const()`) has unbalanced parentheses.
Workaround: change the lambda capture from `[t]` to `[t=t]`.
This code was accepted by clang 3.0.0 but is rejected by all version from 3.1 to the latest trunk currently available on Godbolt.
Godbolt link: https://godbolt.org/z/d87rPjja4
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk1v4zYQ_TX0ZbCGREmWdfDBcda9tT0E6JmixhKzFOnlR9zsry-Gkr-ySbooGgiJQg5nHt97Q0p4r3qDuGHVA6seFyKGwbqNaFt8fV60tnvdPA0IB6u1PSnTg7QdgvIgpMRjwA7aV7BhQAfSjkel0XloYwCHzyjneamF6ZcAlAmdsw5G9F70UyJoVYATKtctWfbIsu38e5VNz47xB3rSaMDxqEVAVuzC6xGNGBGeWPF1mn2xqo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