<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Function in non-type template param causes undefined reference with debug build"
   href="https://bugs.llvm.org/show_bug.cgi?id=45804">45804</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Function in non-type template param causes undefined reference with debug build
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lightborn@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>```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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>