<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54814>54814</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang prohibits initialization of static members of specialized __declspec(dllexport) class templates
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          EAirPeter
      </td>
    </tr>
</table>

<pre>
    The following snippet is accepted by MSVC, while rejected by clang (or clang-cl).
```cpp
template<class>
struct __declspec(dllexport) Foo
{
    static int bar;
};

template<>
int Foo<int>::bar = 0;
```
The following is what clang complains about.
```
foo.cpp:8:15: error: explicit specialization of 'bar' after instantiation
int Foo<int>::bar = 0;
              ^
foo.cpp:4:16: note: implicit instantiation first required here
    static int bar;
               ^
1 error generated.
```
It does not make sense to me, since that declaration is definitely not an instantiation. This error effectively prohibits any initialization of static members of `__declspec(dllexport)` class template specializations.
Note: clang (or clang-cl) accepts the code if we removed `__declspec(dllexport)`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVE1v2zAM_TXyhajhr3wdfEiTFthhw4AVuxayTMfaZMmT5KbZrx9luw0SLOhmKAllUeR7j2QqU5_KpxahMUqZo9QHcFr2PXqQDrgQ2HusoTrB52_fdyzbwbGVCsHiDxTziVCcrrFsbexk3wnFsk3Mkj1LtmyZTEv0_fTGY9cr7pHlO3J3juUP04HzdhAenp9rFMr1KChmrRS-9sZ6igiPxsxBV_eTAfQ4z70UILWHiluW37_57M_2deL3nOFWCJvvyApv8y0tigMs30NyjvBGY9peSkZSHVvuZyWECWmkJv0qM_hrHaZtY0wcFMm3a_qkC_oCtNbY0XjtlRTSQxBBciV_E0OjwTQk8yqQzFbAG4-WWBN97eXo8H-U4OJhi4drZEVAtgyAtAmqbUF2M7CLtNBI6zz1xK9BWuqJFi1-WB64kT6dZIADarRUrPrv-n3yUBt0ARl0_CeCQ-0QvIEOQ5s6qQVtQ1VCN3E7IaVK1dhILT2q03iZ60syMTy15DWBwKahNpcvwbm3ppWV9FRWfYIQ4rIyM88OuwqtG2u1TG72Mp3B2P3w1pVXxXYz7y-z9DembJ5RCkMdKUyNIBs4hgHtzAvV4gMMcVSXeb3JNzzy0issd2OaM9d_4fkOnPLdHt5Lti4arCpb73sX-jN7pHWQvh2qmOaHNkq9vP3cEZzwd0Nb6dyAjoxFsU6LqC3ztOFVUadFxgWKRvBNVm2KZM3TRb5aLNNI8QqVK9ninmWZxiOMIchmi30kyyzJsoT80yJZFlmcr5PVZr2pEUXdrHHJigQ7LlUccMTGHiJbjpCq4eDoUEnn3fmQGMqDRhzTUXw--NbY8mEr7VekcY3G5OUI_g8Js7-U">