Issue |
155376
|
Summary |
Error calling a function template after reinterpret_cast of a static variable
|
Labels |
new issue
|
Assignees |
|
Reporter |
Fedr
|
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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs