[libcxx-commits] [libcxx] [libc++] Introduce a new attribute keyword for Clang improves compatibility with Mingw-GCC (PR #141040)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 23 06:36:41 PDT 2025
mstorsjo wrote:
> > So if we, hypothetically, would have the resources/energy to do so, would we fix it in GCC by making the dllexport apply to the nested class too?
>
> It's possible to both approach - to export or not to import. I consider it's appropriate to export inner classes as align to their outer template instantiation, but opposite is also an option like MSVC does. If GCC may do latter is considered, better not to export currently them as once they're exported, can't be removed (though, will not issue to leave them exported).
That's true. However I think it's less probable that they would change in which cases things are instantiated (as it is mostly consistent across mingw and linux right now - the only inconsistency in GCC is where dllexport applies).
> > In practice, I think it's not all that common to use this construct (explicit template instantiations with nested classes), outside of the standard library.
>
> LLVM itself has such instantiations but won't matter as `__declspec(dllexport)` isn't used for MinGW.
>
> `Registry<T>` has `class iterator`
>
> https://github.com/llvm/llvm-project/blob/989aadf4b112ef55648d801c4003b63f8aad930e/llvm/include/llvm/Support/Registry.h#L150
>
>
> `GenericDomTreeUpdater<...>` has `struct DomTreeUpdate`
> https://github.com/llvm/llvm-project/blob/989aadf4b112ef55648d801c4003b63f8aad930e/llvm/include/llvm/Analysis/DomTreeUpdater.h#L120-L122
>
> https://github.com/llvm/llvm-project/blob/989aadf4b112ef55648d801c4003b63f8aad930e/llvm/include/llvm/Analysis/GenericDomTreeUpdater.h#L23-L24
>
> The cases of satisfy all of conditions (MinGW, built to DLL, use of `__declspec(dllexport)`, instantiate explicitly a class template contains a class that has a member function or a static data member and export it) is rare but could be seen.
Oh, good to know! Also FWIW, these don't have `__declspec(dllexport)` right now, but there is an effort ongoing to annotate all the LLVM APIs with suitable attributes for dllexport/import (to make DLL builds feasible with MSVC). So we may need to take this into account at some point too...
https://github.com/llvm/llvm-project/pull/141040
More information about the libcxx-commits
mailing list