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: unassignedclangb...@nondot.org
          Reporter: lightb...@gmail.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to