<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/129778>129778</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Lambdas as non‐type template parameters cause link errors (.rodata._ZTAXtl3$_0EE defined in discarded section)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ryanofsky
</td>
</tr>
</table>
<pre>
I am encountering a linker error with Clang 19.1.4 when using lambdas as non‐type template parameters across multiple translation units. The minimal example below compiles without issues using GCC and also _does not_ trigger the link error in Clang when optimizations (`-O`) are enabled or if I change the parameter from `const auto&` to `auto` (i.e., pass by value rather than by const reference).
Error:
```c++
`.rodata._ZTAXtl3$_0EE' referenced in section `.text' of pass_b.o: defined in discarded section `.rodata._ZTAXtl3$_0EE[_ZTAXtl3$_0EE]' of pass_b.o
```
(`_ZTAXtl3$_0EE` demangles to `template parameter object for $_0{}`.)
Command to reproduce:
```bash
clang++ -std=c++20 pass_a.cpp pass_b.cpp
```
Example code:
__pass.h__
```c++
#ifndef PASS_H
#define PASS_H
void PassArg(const auto& arg)
{
}
template<auto object>
void PassTemplate()
{
PassArg(object);
}
#endif
```
__pass_a.cpp__
```c++
#include "pass.h"
constexpr auto fn_a = []{};
void pass_a()
{
PassTemplate<fn_a>();
}
int main(int, char**)
{
return 0;
}
```
__pass_b.cpp__
```c++
#include "pass.h"
constexpr auto fn_b = []{};
void pass_b()
{
PassTemplate<fn_b>();
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVU1v4zYQ_TX0ZRCBpmzLOujgxE67QIEusDkUvRgjciSxS5ECSeWjv76gpDT2ZrPYAgUEGB7MPL73OJzBEHRriSq2vWXb4wrH2Dlf-Re0rglfX1a1Uy_VJ8AeyEo32khe2xYQjLZfyQN57zw86djBnUHbwrrM1tkGnjqyMIaUa7CvFQbAANZZdhJsz1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