-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Clang keeps complain it ignores __declspec(dllexport) of basic_data<void> template instantitation definition in format.cc #2220
Conversation
Clang keeps complain it ignores __declspec(dllexport) in format.cc's instantiation of "detail::basic_data<void>;" ``` C:/Users/User/AppData/Roaming/fmt-master/src/format.cc:58:17: warning: 'dllexport' attribute ignored on explicit instantiation definition [-Wignored-attributes] template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>; ^ C:/Users/User/AppData/Roaming/fmt-master/include\fmt/core.h:228:37: note: expanded from macro 'FMT_INSTANTIATION_DEF_API' # define FMT_INSTANTIATION_DEF_API FMT_API ^ C:/Users/User/AppData/Roaming/fmt-master/include\fmt/core.h:210:32: note: expanded from macro 'FMT_API' # define FMT_API __declspec(dllexport) ^ 1 warning generated. ``` I guess we have to make an explicit instantiation definition of `basic_data<void>` in format.cc (without `__declspec(dllexport)` ) and make an explicit instantiation declaration (aka `extern template`) in format.h instead
Add the template instantiation **declaration** of `basic_data<void>` the the template instantiation **definition** is in `format.cc`
Or should I move |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you post the full warning message that you get? Also there are some CI failures.
Try remove FMT_INSTANTIATION_DEF_API from extern template
Fix removing the entire declaration because at line 999 there is one. CI Error in macOS.
By the way, this still does not succeed. It fails on However it's perhaps a clang 12 or mingw64 bug. |
include/fmt/core.h
Outdated
@@ -206,6 +206,7 @@ | |||
|
|||
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32) | |||
# define FMT_CLASS_API FMT_MSC_WARNING(suppress : 4275) | |||
# define FMT_INSTANTIATION_DEF_API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot just remove __declspec(dllexport)
because it will break a shared library. Instead it should be applied to a declaration that can be added to format.cc
.
It seems there might has been some changes. [MinGW] Fix dllexport of explicit template instantiation To fix
|
FMT_INSTANTIATION_DEF_API follows FMT_API
D61118 : make dllexport on extern template, not the instantiation definition in format.cc [MinGW] Fix dllexport of explicit template instantiation https://reviews.llvm.org/D61118
Move FMT_INSTANTIATION_DEF_API to the declaration in format.h [MinGW] Fix dllexport of explicit template instantiation https://reviews.llvm.org/D61118
More over, FMT_INSTANTIATION_DEF_API shall be considered to be renamed. |
Sure |
@@ -55,7 +55,7 @@ vformat_to(buffer<char>&, string_view, | |||
type_identity_t<char>>>); | |||
} // namespace detail | |||
|
|||
template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>; | |||
template struct detail::basic_data<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a short comment saying that clang doesn't allow __declspec(dllexport)
here.
Rename FMT_INSTANTIATION_DEF_API to FMT_INSTANTIATION_DECL_API [MinGW] Fix dllexport of explicit template instantiation https://reviews.llvm.org/D61118
Rename FMT_INSTANTIATION_DEF_API to FMT_INSTANTIATION_DECL_API [MinGW] Fix dllexport of explicit template instantiation https://reviews.llvm.org/D61118
Add a comment that clang now doesn't allow dllexport on template instantiation definitions. Mark them on tempalte instantiation declarations instead (in format.h). [MinGW] Fix dllexport of explicit template instantiation https://reviews.llvm.org/D61118
A comment is added but please feel free to edit it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just one remaining nit.
src/format.cc
Outdated
@@ -55,7 +55,8 @@ vformat_to(buffer<char>&, string_view, | |||
type_identity_t<char>>>); | |||
} // namespace detail | |||
|
|||
template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>; | |||
// Clang doesn't allow dllexport on template instantiation definitions (LLVM D61118) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please add . at the end of the sentence and apply clang-format.
Thanks |
Remove
__declspec(dllexport)
from the definitionand add template instantiation declaration (aka
extern
) informat.h
I'm not sure the added position is correct, please check if it's okey.