<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 - Debug info generates undefined reference for template value which causes linker failure"
   href="https://bugs.llvm.org/show_bug.cgi?id=40307">40307</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Debug info generates undefined reference for template value which causes linker failure
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>brock.wyma@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat global-template-value.cpp
template <const char* U> struct One {
  static const char string [4];
};

int main() {
  One< One<nullptr>::string > one;
  return 0;
}

The GNU compiler compiles/links this code and produces debug information for
the template value parameter "U" with no location:
$ g++ -g global-template-value.cpp
$ readelf -wi a.out
...
 <2><6e>: Abbrev Number: 8 (DW_TAG_template_value_param)
    <6f>   DW_AT_name        : U
    <71>   DW_AT_type        : <0xaf>
...

With no debug information CLANG compiles/links the code with a helpful warning
message:
$ clang++ global-template-value.cpp
global-template-value.cpp:6:22: warning: instantiation of variable
      'One<nullptr>::string' required here, but no definition is available
      [-Wundefined-var-template]
  One< One<nullptr>::string > one;
                     ^
global-template-value.cpp:2:21: note: forward declaration of template entity is
      here
  static const char string [4];
                    ^
global-template-value.cpp:6:22: note: add an explicit instantiation declaration
to
      suppress this warning if 'One<nullptr>::string' is explicitly
instantiated
      in another translation unit
  One< One<nullptr>::string > one;
                     ^
1 warning generated.

But when debug information is enabled CLANG fails to link:
$ clang++ -g global-template-value.cpp
...
/tmp/global-template-value-5c4370.o:(.debug_info+0x78): undefined reference to
`One<(char const*)0>::string'
clang-8: error: linker command failed with exit code 1 (use -v to see
invocation)

The linker failure is caused because of a global variable reference in the
debug metadata here:
!21 = !DITemplateValueParameter(name: "U", type: !22, value: [4 x i8]*
@_ZN3OneILPKc0EE6stringE)

Obviously if the global had been defined in the source then the debug
information would link correctly, but it seems more friendly to emit the
DW_TAG_template_value_param with no location like GCC does.</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>