<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119046>119046</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Linker error after immediate escalation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
LHLaurini
</td>
</tr>
</table>
<pre>
Found this while investigating #118560. This (started from libc++ `std::visit`, now reduced beyond recognition)
```c++
struct S {
consteval void operator()() {}
};
template <class Fn>
constexpr void dispatch(Fn fn) {
fn();
}
template <class Visitor>
struct value_visitor {
constexpr void operator()() { visitor(); }
Visitor&& visitor;
};
template <class Visitor>
constexpr auto make_dispatch() {
return dispatch<value_visitor<S>>;
}
template <class Visitor>
constexpr void visit(Visitor&&) {
make_dispatch<Visitor>();
}
int main() { visit(S{}); }
```
results in a linker error:
```
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-02182a.o: in function `auto make_dispatch<S>()':
<source>:19:(.text._Z13make_dispatchI1SEDav[_Z13make_dispatchI1SEDav]+0x7): undefined reference to `void dispatch<value_visitor<S> >(value_visitor<S>)'
```
GCC accepts it without issue. [Compiler Explorer link](https://godbolt.org/z/hMjj67j8b).
Issue seems related to immediate escalation, as making `make_dispatch` or `visit` `consteval` solves the issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVUGPqzYQ_jXOZRRk7EDIgUNCHu2TXk9b9dDLyphJ8D5jI9uwef31lSG7m2yzh0qIxHj8zcz3zYyF9-psEEuSHUh2XIkxdNaVP37_IUanjFo1tv1V1nY0LYROeXjtlEZQZkIf1FkEZc5AGE_TIstpAn9GG8IKH4QL2MLJ2R60aiRhB8IOQHLqQ0v4nvD9pLwKJKeEVWDsKzhsR4ktNPjLmhYcSns2KihrCNsRuo-m83MFI3Tvgx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