[llvm-bugs] [Bug 45804] New: Function in non-type template param causes undefined reference with debug build
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue May 5 07:01:26 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45804
Bug ID: 45804
Summary: Function in non-type template param causes undefined
reference with debug build
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: lightborn at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
```cpp
void func1(int x);
template<void(&f)(int)>
void func2() { }
int main() {
func2<func1>();
}
```
clang++-9 ref.cxx -g
/tmp/ref-970157.o:(.debug_info+0x67): undefined reference to `func1(int)'
clang: error: linker command failed with exit code 1 (use -v to see invocation
The LLVM function symbol in DITemplateValueParameter apparently ODR uses that
function:
!DITemplateValueParameter(name: "f", type: !18, value: void (i32)* @_Z5func1i)
For non-type template params that bind to a declaration, it seems you can just
pass an appropriately typed nullptr as the Val argument of
DIBuilder::createTemplateValueParameter:
!DITemplateValueParameter(name: "f", type: !18, value: void (i32)* null)
Of course when you pass null you lose introspection of the parameter in the
debugger.
gcc manages to get the best of both worlds somehow:
If func1 is undefined the program still links, but there's no introspection of
f in the debugger.
If func2 is externally defined.. or its defined as inline and ODR used inside
the TU, it both links and gives you introspection in the debugger.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200505/52c1d3bd/attachment.html>
More information about the llvm-bugs
mailing list