<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 --- - __attribute__((used)) ignored in templated classes"
   href="http://llvm.org/bugs/show_bug.cgi?id=17480">17480</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__attribute__((used)) ignored in templated classes
          </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>Windows XP
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm@meinersbur.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Test program test.cpp:

    static __attribute__((used)) void Afunc() {}

    class testclass2 {
        __attribute__((used)) void Bfunc() {}
    };
    testclass2 xxx;

    template<typename T>
    class testclass3 {
       __attribute__((used)) void Cfunc() {}
    };
    testclass3<int> yyy;


<span class="quote">> clang test.cpp -c -o test.obj
> nm test.obj</span >

00000000 b .bss
00000000 d .data
00000000 t .text
00000000 t .text$_ZN10testclass25BfuncEv
00000000 t __ZL5Afuncv
00000000 T __ZN10testclass25BfuncEv
00000000 B _xxx
00000001 B _yyy


I expected to see the mangled name of funcC ("__ZN10testclass25CfuncEv") as
well in the object file. Same result with explicit instantiation instead of
using it:

    template class testclass3<int>;


The culprit seems to be in CodeGeneratorImpl::HandleTagDeclDefinition(). It
calls Method->doesThisDeclarationHaveABody(), but the body is not instantiated
until the end of the translation unit when Sema::PerformPendingInstantiations()
get called.

Using clang r191953 on Windows 7 targeting i686-pc-mingw32</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>