<xhash>: Fix compiler error when dllexporting a class derived from unordered_set #1639
+58
−0
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.
Fixes #1638.
Ordinarily, member functions of a class template are instantiated "on demand" when they're called. (I always remember this as being what allows
list<T>to not requireoperator<fromT, unless and untillist<T>::sort()is called.) However, if a user derives from a Standard class template, and then__declspec(dllexport)s their derived class, all of the member functions of the Standard class template must be instantiated.This is how #423 caused a regression in VS 2019 16.6.
_Hash::_Multi_equal()is called only for multi containers (unordered_multimapandunordered_multiset), so itstatic_asserts that_Traits::_Multiistrue. However,dllexportcan attempt to instantiate this for the unique containers (unordered_mapandunordered_set).There are several possible fixes, but I felt that the least invasive was to make
_Multi_equal()a member function template. That alone would be sufficient (i.e.template <int = 0>would work), but constraining it to exist for multi containers is simple. I left thestatic_assertalone, as it provides a bit of an explanation, even though it is redundant with the constraint now.I am also adding a regression test, as this is an uncommon but recurring headache in the containers. This covers all of the containers, container adaptors, and views in the Containers clause - which are the most likely to be affected, as they sometimes have conditionally activated code like this. In theory, this test could be extended to cover any Standard type; if we encounter problems in the future, it is easy to extend, but right now having something is better than nothing.