inline function ... is not defined
points to the definition, then get 'undefined reference' · Issue #59734 · llvm/llvm-project (original) (raw)
This is a regression introduced in Clang 15.
template void foo() { & { struct Guard { ~Guard() {} }; Guard guard; }(42); }
int main() { foo(); }
Clang says:
<source>:6:24: warning: inline function 'foo()::(anonymous class)::operator()(int)::Guard::~Guard' is not defined [-Wundefined-inline]
struct Guard { ~Guard() {} };
^
<source>:7:15: note: used here
Guard guard;
^
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/example-a1895d.o: in function `operator()<int>':
<source>:8: undefined reference to `foo<int>()::{lambda(auto:1)#1}::operator()<int>(int) const::Guard::~Guard()'
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
While GCC and MSVC accept this code.
Tested on Clang 15, and on trunk commit a564048899a1a1de526a02cfd1a5d691ec31bafd
.