https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86138
--- Comment #13 from Christian Franke <franke at computer dot org> --- This patch prevents duplicate _S_empty_rep_storage[] even on Cygwin (char only, wchar_t missing). Testcase works as expected then: --- basic_string.tcc.orig 2018-05-03 06:22:46.000000000 +0200 +++ basic_string.tcc 2018-06-21 13:00:03.370070700 +0200 @@ -1597,7 +1597,8 @@ // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. -#if _GLIBCXX_EXTERN_TEMPLATE > 0 && __cplusplus <= 201402L +#if _GLIBCXX_EXTERN_TEMPLATE > 0 +#if __cplusplus <= 201402L extern template class basic_string<char>; extern template basic_istream<char>& @@ -1627,6 +1628,12 @@ basic_istream<wchar_t>& getline(basic_istream<wchar_t>&, wstring&); #endif + +#else + extern template + basic_string<char>::size_type + basic_string<char>::_Rep::_S_empty_rep_storage[]; +#endif #endif On Linux and other platforms using ELF the problem does not occur because template static data members use the GNU extension ".type ... @gnu_unique_object" (nm command prints 'u'). Are there possibly other platforms affected? For example: - ELF based platforms were dynamic linker does not support this GNU extension, or - non ELF based platforms without a similar feature.