[Note: do we need entries in config/abi/pre/gnu.ver for these?]

This declares and defines explicit instantiations of std::syncbuf<T>::
__mutex::_S_get_mutex for T=char and T=wchar_t, where the function
is defined at all, the wchar_t case gated on _GLIBCXX_USE_WCHAR_T.

libstdc++-v3/ChangeLog:
        * include/std/syncstream: Declare 'extern template syncbuf...'
        * src/c++20/syncbuf.cc: Define 'template syncbuf...
        * src/c++20/Makefile.am: Mention syncbuf.cc.
        * src/c++20/Makefile.in: Regenerate.
---
 libstdc++-v3/include/std/syncstream | 11 +++++++-
 libstdc++-v3/src/c++20/Makefile.am  |  2 +-
 libstdc++-v3/src/c++20/Makefile.in  |  2 +-
 libstdc++-v3/src/c++20/syncbuf.cc   | 41 +++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 libstdc++-v3/src/c++20/syncbuf.cc

diff --git a/libstdc++-v3/include/std/syncstream 
b/libstdc++-v3/include/std/syncstream
index e2b5a199ec9..df07934f3b4 100644
--- a/libstdc++-v3/include/std/syncstream
+++ b/libstdc++-v3/include/std/syncstream
@@ -221,7 +221,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _M_mtx->unlock();
        }
 
-       // FIXME: This should be put in the .so
+       // Specializations on char, wchar_t defined in src/c++20/syncbuf.cc .
        static mutex&
        _S_get_mutex(void* __t)
        {
@@ -243,6 +243,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       __mutex _M_mtx;
     };
 
+#if _GLIBCXX_HAS_GTHREADS
+#if _GLIBCXX_EXTERN_TEMPLATE
+  extern template mutex& basic_syncbuf<char>::__mutex::_S_get_mutex(void*);
+#ifdef _GLIBCXX_USE_WCHAR_T
+  extern template mutex& basic_syncbuf<wchar_t>::__mutex::_S_get_mutex(void*);
+#endif
+#endif
+#endif
+
   template <typename _CharT, typename _Traits, typename _Alloc>
     class basic_osyncstream : public basic_ostream<_CharT, _Traits>
     {
diff --git a/libstdc++-v3/src/c++20/Makefile.am 
b/libstdc++-v3/src/c++20/Makefile.am
index 736558ff24a..e90a1ad15b3 100644
--- a/libstdc++-v3/src/c++20/Makefile.am
+++ b/libstdc++-v3/src/c++20/Makefile.am
@@ -30,7 +30,7 @@ headers =
 if ENABLE_EXTERN_TEMPLATE
 # XTEMPLATE_FLAGS = -fno-implicit-templates
 inst_sources = \
-       sstream-inst.cc
+       sstream-inst.cc syncbuf.cc
 else
 # XTEMPLATE_FLAGS =
 inst_sources =
diff --git a/libstdc++-v3/src/c++20/Makefile.in 
b/libstdc++-v3/src/c++20/Makefile.in
index 3cb6d6fea5f..7ead76afa22 100644
--- a/libstdc++-v3/src/c++20/Makefile.in
+++ b/libstdc++-v3/src/c++20/Makefile.in
@@ -430,7 +430,7 @@ headers =
 
 # XTEMPLATE_FLAGS = -fno-implicit-templates
 @ENABLE_EXTERN_TEMPLATE_TRUE@inst_sources = \
-@ENABLE_EXTERN_TEMPLATE_TRUE@  sstream-inst.cc
+@ENABLE_EXTERN_TEMPLATE_TRUE@  sstream-inst.cc syncbuf.cc
 
 sources = tzdb.cc format.cc atomic.cc clock.cc
 @GLIBCXX_HOSTED_FALSE@libc__20convenience_la_SOURCES = 
diff --git a/libstdc++-v3/src/c++20/syncbuf.cc 
b/libstdc++-v3/src/c++20/syncbuf.cc
new file mode 100644
index 00000000000..72c7904245b
--- /dev/null
+++ b/libstdc++-v3/src/c++20/syncbuf.cc
@@ -0,0 +1,41 @@
+// Explicit instantiation file.
+
+// Copyright (C) 2020-2025 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+#include <syncstream>
+
+#if _GLIBCXX_USE_CXX11_ABI
+#if _GLIBCXX_HAS_GTHREADS
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+template mutex& basic_syncbuf<char>::__mutex::_S_get_mutex(void* t);
+#ifdef _GLIBCXX_USE_WCHAR_T
+template mutex& basic_syncbuf<wchar_t>::__mutex::_S_get_mutex(void* t);
+#endif
+
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+#endif // GTHREADS
+#endif // ABI
-- 
2.50.1

Reply via email to