<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Template instantiation fails with undefined reference"
   href="http://llvm.org/bugs/show_bug.cgi?id=20854">20854</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Template instantiation fails with undefined reference
          </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>wpoely86@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12992" name="attach_12992" title="The example that fails">attachment 12992</a> <a href="attachment.cgi?id=12992&action=edit" title="The example that fails">[details]</a></span>
The example that fails

I've make a small piece of code (see attachment) that compiles fine with GCC
4.9.1 and icpc-2015.0.090 but not with Clang-3.5.

I've split up the definition and declaration of a template class in the usual
way: in the cpp file, all templates used have been explicitly Instantiation.
If you put everything in the header, everything works fine.

Clang fails with undefined reference to the template class. If I look at the
symbols in the object file generated by Clang and GCC:
GCC:
0000000000000000 W BlockStructure<Matrix>::BlockStructure(int)
0000000000000000 W BlockStructure<Matrix>::BlockStructure(int)
0000000000000000 n _ZN14BlockStructureI6MatrixEC5Ei
0000000000000000 W BlockStructure<Matrix>::~BlockStructure()
0000000000000000 W BlockStructure<Matrix>::~BlockStructure()
0000000000000000 W BlockStructure<Matrix>::~BlockStructure()
0000000000000000 n _ZN14BlockStructureI6MatrixED5Ev
0000000000000000 V typeinfo for BlockStructure<Matrix>
0000000000000000 V typeinfo name for BlockStructure<Matrix>
0000000000000000 V vtable for BlockStructure<Matrix>
                 U vtable for __cxxabiv1::__class_type_info
                 U operator delete(void*)

Clang:
0000000000000000 r GCC_except_table1
                 U _Unwind_Resume
0000000000000000 W BlockStructure<Matrix>::~BlockStructure()
0000000000000000 W BlockStructure<Matrix>::~BlockStructure()
0000000000000000 V typeinfo for BlockStructure<Matrix>
0000000000000000 V typeinfo name for BlockStructure<Matrix>
0000000000000000 V vtable for BlockStructure<Matrix>
                 U vtable for __cxxabiv1::__class_type_info
                 U operator delete(void*)
                 U __gxx_personality_v0

It seems like Clang skips the instantiation of the templates with expecting of
the destructor?</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>