Issue 56068
Summary MSVC incompatibility for dllimport/dllexport and function-local classes
Labels clang:frontend, platform:windows
Assignees
Reporter pogo59
    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> {};
}
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to