Issue |
129693
|
Summary |
[Clang] Build fails when forward declared static template function used in std::visit
|
Labels |
clang
|
Assignees |
|
Reporter |
deaklajos
|
Code:
```cpp
#include <variant>
template<typename T>
static T funcT(const T t);
int main()
{
std::variant<int, double> v{1};
return std::visit([&](auto& a) -> int
{
return funcT<>(a);
}, v);
}
template<typename T>
static T funcT(const T t) {
return t;
}
```
Output:
```
<source>:4:10: warning: function 'funcT<int>' has internal linkage but is not defined [-Wundefined-internal]
4 | static T funcT(const T t);
| ^
<source>:12:16: note: used here
12 | return funcT<>(a);
| ^
<source>:4:10: warning: function 'funcT<double>' has internal linkage but is not defined [-Wundefined-internal]
4 | static T funcT(const T t);
| ^
<source>:12:16: note: used here
12 | return funcT<>(a);
| ^
2 warnings generated.
ASM generation compiler returned: 0
<source>:4:10: warning: function 'funcT<int>' has internal linkage but is not defined [-Wundefined-internal]
4 | static T funcT(const T t);
| ^
<source>:12:16: note: used here
12 | return funcT<>(a);
| ^
<source>:4:10: warning: function 'funcT<double>' has internal linkage but is not defined [-Wundefined-internal]
4 | static T funcT(const T t);
| ^
<source>:12:16: note: used here
12 | return funcT<>(a);
| ^
2 warnings generated.
/opt/compiler-explorer/gcc-14.2.0/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8f2a9c.o: in function `int main::$_0::operator()<int>(int&) const':
<source>:12:(.text+0x257): undefined reference to `int funcT<int>(int)'
/opt/compiler-explorer/gcc-14.2.0/lib/gcc/x86_64-linux-gnu/14.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-8f2a9c.o: in function `int main::$_0::operator()<double>(double&) const':
<source>:12:(.text+0x309): undefined reference to `double funcT<double>(double)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Execution build compiler returned: 1
```
Demo: https://godbolt.org/z/d18dvc56E
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs