Fix VtArray declaraions of extern template instantiations so that the… #2415
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.
Fix VtArray declaraions of extern template instantiations so that the code in array.cpp will actually instantiate and export the templates as expected. Currently the templates are marked as extern even while compiling array.cpp so the compiler isn't actually instantiating anything. This problem seems to only apply to Windows builds.
Description of Change(s)
The existing code in vt/array.cpp doesn't actually generate exported symbols for some compilers as demonstrated here: https://godbolt.org/z/Gz1vc5eEe
The array.h file should be using the VT_API_TEMPLATE_CLASS macro so that when compiling array.cpp there is no confusion about whether code should be generated to instantiate the templates. In array.cpp VT_API must be added explicitly to the instantiation macro to ensure the generated symbols are exported.
Note that for many compilers there are many configurations here that all seem to work okay, either because of inlining of VtArry functions, or different interpretations of classes defined first as extern in the header, then non-extern in the cpp.
Thanks go to @e4lam for pointing this out.