-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Clang-cl has inconsistent behavior compared to MSVC for __declspec(dllexport) template specialization #54717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A known workaround is to place template<>
__declspec(dllexport) void Foo<int>::Bar() {} But IMO, it would be better to have clang-cl be in sync with MSVC's behavior when dealing with MS specific features. |
Thanks for the bug! Slightly trimmed reproducer:
The attribute gets dropped in
and we have tests which expect that behaviour in The tests go back a long time though, to 755a36f. Maybe MSVC has changed since then, or maybe the tests didn't get it quite right. |
Testing with MSVC 18.00.21005.1 which is from that era, the function still got exported. I think the tests just happen to reflect how Clang behaved at the time, i.e. it dropped all attributes for explicit specializations, and then e497438 kept that behavior for dllexport because of the tests. |
We should also consider the dllimport case. clang-cl accepts this:
But MSVC does not:
It works if we make it a declaration though:
MSVC accepts that and treats the function as dllimport; clang-cl accepts it but does not treat it as dllimport. |
I'm still working on this. The dllimport side is a bit subtle. Also we need to differentiate between
Furthermore, I ran into some old bugs while digging around here, #21780 and #20510. Maybe we can fix those at the same time, or we should at least not make them worse. |
The test case above is more illustrative than I thought. The latter case is what clang's tests covered. The former case was not covered by tests, and was handled incorrectly. |
…class template member functions Previously we were stripping these normally inherited attributes during explicit specialization. However for class template member functions (but not function templates), MSVC keeps the attribute. This makes Clang match that behavior, and fixes GitHub issue #54717 Differential revision: https://reviews.llvm.org/D135154
A short reproduction of this issue is given below.
When compiled with
clang-cl foo.cpp /link /dll /out:foo.dll
, I get no exported symbols fromfoo.dll
(by runningdumpbin /exports foo.dll
), which would result in further link errors in our code base.While there is a
?Bar@?$Foo@H@@QEAAXXZ
entry in exports withcl foo.cpp /link /dll /out:foo.dll
.My clang version is
13.0.1
.Hopefully LLVM can get this resolved.
The text was updated successfully, but these errors were encountered: