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

    <tr>
        <th>Summary</th>
        <td>
            MSVC incompatibility for dllimport/dllexport and function-local classes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            platform:windows
      </td>
    </tr>

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

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

<pre>
    MSVC appears to have decided that dllimport/dllexport force external linkage, while Clang decided they are incompatible with external linkage.  MSVC also documents that a dllimport/dllexport derived class with a templated base class causes the base class instantiation to inherit the dllimport/dllexport attribute.

(I don't see a way to add an attachment so the exhausting test case pasted inline.)
```
#define IMPORT __declspec(dllimport)
#define EXPORT __declspec(dllexport)
class Base {};
class IMPORT ImportedBase {};
class EXPORT ExportedBase {};
template<class T> class TmplBase {};
template<class T> class IMPORT ImportedTmplBase {};
template<class T> class EXPORT ExportedTmplBase {};

void dummy() {
  // Both compilers are happy with these.
  class LocalBase : public Base {};
  class LocalImportedBase : public ImportedBase {};
  class LocalExportedBase : public ExportedBase {};
  class LocalTmplBase : public TmplBase<int> {};
  class LocalImportedTmplBase : public ImportedTmplBase<int> {};
  class LocalExportedTmplBase : public ExportedTmplBase<int> {};
  class LocalCRTP : public TmplBase<LocalCRTP> {};

  // Clang complains about all of the rest.
  class IMPORT ImportedLocalBase : public Base {};
  class IMPORT ImportedLocalImportedBase : public ImportedBase {};
  class IMPORT ImportedLocalExportedBase : public ExportedBase {};
  class IMPORT ImportedLocalTmplBase : public TmplBase<int> {};
  class IMPORT ImportedLocalImportedTmplBase : public ImportedTmplBase<int> {};
  class IMPORT ImportedLocalExportedTmplBase : public ExportedTmplBase<int> {};

  class EXPORT ExportedLocalBase : public Base {};
  class EXPORT ExportedLocalImportedBase : public ImportedBase {};
  class EXPORT ExportedLocalExportedBase : public ExportedBase {};
  class EXPORT ExportedLocalTmplBase : public TmplBase<int> {};
  class EXPORT ExportedLocalImportedTmplBase : public ImportedTmplBase<int> {};
  class EXPORT ExportedLocalExportedTmplBase : public ExportedTmplBase<int> {};

  class IMPORT ImportLocalCRTP : public TmplBase<ImportLocalCRTP> {};
  class EXPORT ExportLocalCRTP : public TmplBase<ExportLocalCRTP> {};

  // CRTP where template is dllimport/dllexport gets an extra Note.
  class IMPORT ImportImportLocalCRTP : public ImportedTmplBase<ImportImportLocalCRTP> {};
  class IMPORT ImportExportLocalCRTP : public ExportedTmplBase<ImportExportLocalCRTP> {};
  class EXPORT ExportImportLocalCRTP : public ImportedTmplBase<ExportImportLocalCRTP> {};
  class EXPORT ExportExportLocalCRTP : public ExportedTmplBase<ExportExportLocalCRTP> {};
}
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytV21v2jAQ_jXhy2koJLx-yIdCO6nS3rRV075VTnwQb8aOYqeUf79zEkpJDYNRCUHI3T333N1jx0k13yaff_xcACsKZKUBqyFnTwgcM8GRg82ZBS6lWBe6tEH0ka7x2V3DUpcZAj5bLBWTIIX6w1YYRAvY5EIiLCRTq1dAuAVWIgiV6XXBrEjJZyNs_gaiD9BwkkYD11m1RmVNQ4UdIcOxFE-UJpPMmAaWgcV1IZml2ykz2NoyVhl0aPj6rlDGMmUF8dLKdUGonCBt7edPyawtRVpZ7AfhbRDetN_R9J5IqyCaWDCIRGPDtg6RcQ5MuTCW5a4koPIcPD7nxMkK6pZFY4kh0SqYccSFoqZQhmjWwo_D9tNmizkuyQPuP3_7-v0BHh-p4dIUmBGRV7xnXf-7X17_prYX_6Y5c0comMyDyW0Qz19b2qz3dRbkxx3bdHfPxx130wriRRPzEMR37XgeyHRpTIfb_0B0WB-DaL6ftODAq_V6S62kDtZetQWAhEMfmGvSpZM_rQ9abG455LTyto1gSQtmJyZoGXzSGWtzxjdQVKkUmXceBwGH89gHnprTAcDhnPYAp-Z3ALBv1T54d486LZR1XT6nBh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