<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155376>155376</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Error calling a function template after reinterpret_cast of a static variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fedr
</td>
</tr>
</table>
<pre>
This program
```c++
template<auto E>
void test2() {
++*E;
}
template<typename T>
char test1() {
static char a[16];
static T& ref = *reinterpret_cast<T*>(a);
test2<a>();
test2<&ref>();
return a[0];
}
int main() {
return test1<int>();
}
```
is accepted in GCC and MSVC.
But Clang 20.1 rejects it with
```
<source>:11:5: error: no matching function for call to 'test2'
11 | test2<&ref>();
| ^~~~~~~~~~~
<source>:16:12: note: in instantiation of function template specialization 'test1<int>' requested here
16 | return test1<int>();
| ^
<source>:2:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'E'
2 | void test2() {
| ^
```
Online demo: https://gcc.godbolt.org/z/o9WsvE33e
Clang trunk shows the same error in C++20 mode, but in C++23 mode, the program compiles fine but a linker error appears:
```
undefined reference to `test1()::a'
```
Online demo: https://gcc.godbolt.org/z/4Mzaczo3e
Original report: https://stackoverflow.com/q/79745946/7325599
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVU-To7YT_TTypWtdIFkwHDgwjP07be3hN5UcU7LUGGWExErCk5lDPntKgP_szCY5xEVhilY_vdfdeogQ9Mki1oQ_Ev60EVPsna8PqPzm6NRb_dzrAKN3Jy8GkjWkyJZLEvqYrqyJOIxGRCSsFVN0sCdsT7Lm7LSCiCFSQh8IrYCUaTUAwJpKmz1h6R0pn9L9B6j4NqIVA8LzAid74We4_BNciCJqCfMKQfhjXhD-tCDfhZ8JLcBjB4Q9AaGNR20j-tFj_E2KEAlrnwlt0m70QRBa3RAWFawVS_AWuwQILTx2H6MA4DFO3s6ssiupq1xtIw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