-
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
Fix DLL visibility of explicit instantiation "declaration" of internal::basic_data<void> in header format.h and the explicit instantiation "definition" in format.cc #1134
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
01bb881
Update format.cc
denchat 3944deb
Mirror visibility of explicit instantiation declaration
denchat e4bd8c1
Eliminate `__declspec(dllexport)` designation on extern template inte…
denchat 4f919b8
Add `FMT_EXTERN_TEMPLATE_API` for designate DLL export `extern template`
denchat c6e6bfe
Delete whole `FMT_USE_EXTERN_TEMPLATES` block and its condition
denchat b4a4dcd
Add `#define FMT_EXTERN extern` only when not `FMT_HEADER_ONLY`
denchat 7d0dd76
Replace `extern` on basic_data<void> with the `FMT_EXTERN` condition …
denchat c3d87c5
replace misspelled if !define() with ifndef
denchat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think this is right, e.g. https://godbolt.org/z/kGqqeS gives
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.
Thank you. You are right. It seems the instantiation declaration implicitly has got the same
__declspec(dllexport)
from the class template definition.So we can resolve this at the class template definition alone.
It looks like travis-ci compilation failed by some reason. How can I make them recompile?
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.
My problem is when I tried to compile this code on Windows
The linker can not find
internal::basic_data<void>::ZERO_OR_POWERS_OF_10_32
This is because we were trying to dllexport : explicit class template instantiation "declaration"
but not the explicit class template instantiation "definition" in
format.cc
When doing DLL on extern template instantiation, we have to do something like this.
REF: https://stackoverflow.com/a/46392757/6370128
So we want something like this
godbolt
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.
I don't think
extern
is actually useful here, so I suggest just removing it together with the wholeFMT_USE_EXTERN_TEMPLATES
block.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.
extern
is telling other translation units that they all could rely on the definition ofinternal::basic_data<void>
informat.cc
. So that all translation units usinginternet::basic_dat<void>
, exceptformat.cc
, don't need to instantiate it by themselves. This makes compilation faster. This is the purpose of c++11 explicit class template declaration feature.If
extern
in format.h is removed, so it becomes the definition itself. All translation units usingformat.h
will be required to instantiateinternal::basic_data<vod>
every single time which that doesn't need to, only if using c++11 explicit class template declaration feature.Besides, what about the definition in format.cc? Now there would be already another definition in
format.h
, so the definition informat.cc
must be removed altogether withextern
then.However, if you are affirmed that the explicit class template declaration feature would make lesser benefits than the complexity it'd gain here, I will make the definition stay in
format.h
as you suggested.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.
You are right, it's better to keep
extern template
, but please remove the macroFMT_USE_EXTERN_TEMPLATES
. We already require C++11 and this feature is widely available. Hopefully this will simplify the logic aroundFMT_API
a bit.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.
I've already removed the whole
FMT_USE_EXTERN_TEMPLATES
block.Anyway, I guess
FMT_API
.extern
in front of extern template declaration itself must also have its own condition as well.I'm not any good at naming. I only could come up with
FMT_EXTERN_TEMPLATE_API
andFMT_EXTERN
respectively and make them added incore.h
. Any suggestions are welcome.