[PATCH] D146338: [MSVC compatibility][dllimport/dllexport][PS] Allow dllexport/dllimport for classes with UniqueExternalLinkage

Wolfgang Pieb via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 17 16:27:59 PDT 2023


wolfgangp created this revision.
wolfgangp added reviewers: hans, probinson, mstorsjo.
Herald added a project: All.
wolfgangp requested review of this revision.

This replaces D145271 <https://reviews.llvm.org/D145271>.

Rather than coercing classes with UniqueExternalLInkage to ExternalLinkage as proposed in D145271 <https://reviews.llvm.org/D145271>, this patch suggests to simply allow the dllexport/dllimport attributes for classes that exhibit UniqueExternalLinkage, which includes instantiations of template classes where the template parameters are local classes or classes in anonymous namespaces:

  template <typename T>
  class __declspec(dllimport) A {};
  
  void func()
  {
    class B : public A<B> {};
  }
  
  namespace {
    class C : public A<C> {};
  }

In D145271 <https://reviews.llvm.org/D145271> it was suggested that we drop the attribute in such contexts, and this is effectively what happens. The compiler does not produce any exported definitions (or import any symbols) for such classes. The patch is simply to suppress the diagnostic for MSVC mode and Playstation.

I have not changed the behavior of the Windows/Itanium triple since I wasn't sure if this was desirable.


https://reviews.llvm.org/D146338

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/dllexport.cpp
  clang/test/SemaCXX/dllimport.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146338.506217.patch
Type: text/x-patch
Size: 32749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230317/8ccd9454/attachment-0001.bin>


More information about the cfe-commits mailing list