'extern template class std::vector<FwdDecld>;

I have a class containing a std::vector<FwdDecl> member. I'd like to do

extern template class std::vector<FwdDecld>;

in the header and

template class std::vector<FwdDecld>;

in the .cpp so my class's special member functions can be automatic (rather than declaring all six in the .h and =defaulting all six in the .cpp).

It seems that this works with MSVC and Apple Clang, but not Clang or GCC: https://godbolt.org/z/Tc8G91rj6

This works just fine with boost::container::vector, though: https://godbolt.org/z/j6zfj4K3r

Is this correct? Are GCC and Clang being compliant? Is MSVC?

Related extern template class std::unique_ptr<FwdDecl> does seem to work (although obviously it's not copyable), even when the forward-declared class is private: https://godbolt.org/z/ThhW4fPGE



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source