<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125747>125747</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] failure to instantiate template specialization defined after use when used from generic lambda
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++11,
clang:frontend,
accepts-invalid,
rejects-valid,
diverges-from:gcc,
diverges-from:msvc,
diverges-from:edg
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zygoloid
</td>
</tr>
</table>
<pre>
Reduced testcase:
```c++
template<typename F> constexpr void visit(F f) { f(0); }
template <class T> void G(T t);
int main() { visit([](auto s) -> void { G(s); }); }
template <class T> void G(T t) {}
```
This should compile and link, but [does not](https://godbolt.org/z/94xY8eGWe), because Clang fails to instantiate `G<int>` at the end of the TU. ([Accepts-invalid version](https://godbolt.org/z/hEfdjxT8z) for testsuite).
Because `visit` and the lambda's call operator are `constexpr`, they'll get instantiated immediately, which will trigger an attempt to instantiate `G<int>`, which will fail because it's not defined yet. But it should then get added to the pending instantiations list to be retried at the end of the translation unit, which appears to not be happening in this case.
Curiously, this bug seems to require a lambda -- if the lambda is replaced by an equivalent struct, the [bug disappears](https://godbolt.org/z/v8Wq4osh8). Also, a direct call to the lambda does not trigger the bug; it must be indirectly called via another constexpr function.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVVGv2jgT_TXmZQQKDiHwwANwS98_3U_VPjr2JHHXsVN7TMv99atJuCy92mq7UiQsj318fM4co1KynUc8iOokqpeFytSHeHi7dcEFaxZNMLfD_9BkjQYIE2mVUJRHURzFtpg_LeSJv-JIOIxOEYryTLcRvRoQLqL8BDr4RPhjjHAN1sDVJktC7i7QCrkHUZ94sCuE3IvyBKJ-eQIDUZ61UynBK0NNAJ-F3L0CzetFcbSeYFDWC7l7B3w_Y76YkDuVKUDi8vKBwwsZKz2d_N85MMy8_qGJKI6vvU2Q-pCdAR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