https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80811
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- That does work. I had tried with the attribute on the end of the declaration and it barfed. I was going to say I'd worry that declaring the members extern template might effectively hide them from their bodies optimizer and pessimize other code, but I see that the whole std::string specialization is declared extern template so it's already hidden, which is why the optimization doesn't happen to begin with.