<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 - [clang-cl] __declspec(dllexport) on class declaration implicitly instantiates templates"
   href="https://bugs.llvm.org/show_bug.cgi?id=41895">41895</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[clang-cl] __declspec(dllexport) on class declaration implicitly instantiates templates
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Driver
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>me@mark-ingram.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21952" name="attach_21952" title="Test file">attachment 21952</a> <a href="attachment.cgi?id=21952&action=edit" title="Test file">[details]</a></span>
Test file

Attempting to export a class declaration that will be partially specialised
results in an error:

template<typename T>
class __declspec(dllexport) Foo
{
public:
        static const int Bar;
};

template<> const int Foo<char>::Bar = 42;

Using clang-cl:

$ clang-cl -c test.cpp
test.cpp(8,33):  error: explicit specialization of 'Bar' after instantiation
template<> const int Foo<char>::Bar = 42;
                                ^
test.cpp(5,19):  note: implicit instantiation first required here
        static const int Bar;
                         ^
1 error generated.

Using cl:
<span class="quote">> cl /c test.cpp /nologo</span >
test.cpp



The work around that I have is to export individual class members, which
prevents the implicit template instantiation, and allows a subsequent partial
template specialisation.

Also, the diagnostic isn't quite right, because the implicit instantiation
happens when the class is exported, not when the member is defined (removing
the __declspec(dllexport) allows the code to compile with clang-cl).</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>