[PATCH] D145271: [MSVC compatibility][DLLEXPORT/DLLIMPORT] Allow dllexport/dllimport for local classes

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 02:46:05 PST 2023


hans added a reviewer: mstorsjo.
hans added a comment.

+mstorsjo for thoughts about Windows code, even if this might not apply to mingw.

In D145271#4172636 <https://reviews.llvm.org/D145271#4172636>, @wolfgangp wrote:

> A customer complained about the following code (I'm obscuring the class names) compiling with MSVC but
> rejected by clang:
>
>   template <class T>
>   class __declspec(dllimport) A
>   {
>   };
>   
>   void func()
>   {
>     // local class with internal linkage
>     class B: public A<B>
>     {
>     };
>   }

Oh I see, it's not intentionally trying to dllimport/export a local class, the problem is really dllimport/exporting a class template instantiated with a local class as template argument.

The problem can be hit without inheritance too:

  template <typename> struct __declspec(dllimport) Base { };
  
  void f() {
    struct Local { };
    Base<Local> x;
  }
  
  error: 'Base<Local>' must have external linkage when declared 'dllimport'

It still seems like the export/import there is an accident since `Base<f::Local>` can't really be referenced from outside the file anyway.

Perhaps rather than giving `Base<f::Local>` external linkage to allow it to be imported/exported, the better fix would be to drop its dllimport/export attribute when instantiated with a local type?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145271/new/

https://reviews.llvm.org/D145271



More information about the llvm-commits mailing list