]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Split <iosfwd> and only include it in <ios> [PR125371]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 19 May 2026 15:51:14 +0000 (16:51 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 26 May 2026 10:13:59 +0000 (11:13 +0100)
The standard explicitly requires the <ios> header to include <iosfwd>,
which has declarations of all the standard stream buffers and stream
types. Because we include <ios> in <istream> and <ostream>, this means
that <iosfwd> is included everywhere, and so every iostream header has a
forward declaration of every iostream type. This means that for example,
<fstream> has a declaration (but not the definition) of std::stringbuf.

This leads to a poor user experience, because the compiler's fixit hints
for undeclared types do not trigger of the type _has_ been declared,
instead users get an error about using an incomplete type. See the
example in PR 125371, where using std::istringstream after including
<fstream> fails to suggest including <sstream>.

If we stop including <ios> in <istream> and <ostream>, and instead
include _most_ of the same things that <ios> provides, then we can avoid
the unhelpful declarations of the entire family of iostream types in
every header. Users who really do want a declaration of std::filebuf
or std::istringstream (but don't want the full definition) can still
explicitly include <iosfwd> to get those declarations. But they won't
get them as a side effect of <fstream> etc.

Various headers currently include <iosfwd> because they really do want
the declaration of e.g. std::ostream of std::streambuf_iterator. We can
split <iosfwd> into five smaller headers and then only include the relevant
one where required, e.g. <fstream> only needs to include iosfwd_file.h
and not iosfwd_string.h.

We need to add an explicit include of <ios> in <iostream>.  The standard
requires it there, and after this change we no longer get it via
<istream> and <ostream>.

libstdc++-v3/ChangeLog:

PR libstdc++/125371
* config/io/basic_file_stdio.h: Include <bits/ios_base.h>
instead of <ios>.
* include/Makefile.am: Add new headers.
* include/Makefile.in: Regenerate.
* include/bits/fs_path.h: Include <bits/iosfwd.h> instead of
<iosfwd>.
* include/bits/locale_facets.h: Remove unused <iosfwd> and
<streambuf> includes.
* include/bits/localefwd.h: Include <bits/iosfwd.h> instead of
<iosfwd>.
* include/bits/ostream.h: Replace <ios> with its constituent
parts, except for <iosfwd>.
* include/bits/ostream_insert.h: Include <bits/iosfwd.h> instead
of <iosfwd>.
* include/bits/shared_ptr.h: Likewise.
* include/bits/std_thread.h: Likewise.
* include/bits/stream_iterator.h: Likewise.
* include/std/fstream: Include <bits/iosfwd_file.h>.
* include/std/iomanip: Include <bits/iosfwd.h> instead of
<iosfwd>.
* include/std/ios: Do not include <exception> or
<bits/char_traits.h>.
* include/std/iosfwd: Move declarations to new headers and
include those new headers. Tweak Doxygen comment.
* include/std/iostream: Include <ios>.
* include/std/istream: Replace <ios> with its constituent
parts, except for <iosfwd>.
* include/std/random: Include <bits/iosfwd.h> instead of
<iosfwd>.
* include/std/spanstream: Include <bits/iosfwd_span.h>.
* include/std/sstream: Include <bits/iosfwd_string.h>.
* include/std/streambuf: Include <bits/iosfwd.h> instead of
<iosfwd>.
* include/std/string_view: Likewise.
* include/std/syncstream: Include <bits/iosfwd_sync.h>.
* include/std/system_error: Include <bits/iosfwd.h> instead of
<iosfwd>.
* include/bits/iosfwd.h: New file.
* include/bits/iosfwd_file.h: New file.
* include/bits/iosfwd_span.h: New file.
* include/bits/iosfwd_string.h: New file.
* include/bits/iosfwd_sync.h: New file.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
29 files changed:
libstdc++-v3/config/io/basic_file_stdio.h
libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/include/bits/iosfwd.h [new file with mode: 0644]
libstdc++-v3/include/bits/iosfwd_file.h [new file with mode: 0644]
libstdc++-v3/include/bits/iosfwd_span.h [new file with mode: 0644]
libstdc++-v3/include/bits/iosfwd_string.h [new file with mode: 0644]
libstdc++-v3/include/bits/iosfwd_sync.h [new file with mode: 0644]
libstdc++-v3/include/bits/locale_facets.h
libstdc++-v3/include/bits/localefwd.h
libstdc++-v3/include/bits/ostream.h
libstdc++-v3/include/bits/ostream_insert.h
libstdc++-v3/include/bits/shared_ptr.h
libstdc++-v3/include/bits/std_thread.h
libstdc++-v3/include/bits/stream_iterator.h
libstdc++-v3/include/std/fstream
libstdc++-v3/include/std/iomanip
libstdc++-v3/include/std/ios
libstdc++-v3/include/std/iosfwd
libstdc++-v3/include/std/iostream
libstdc++-v3/include/std/istream
libstdc++-v3/include/std/random
libstdc++-v3/include/std/spanstream
libstdc++-v3/include/std/sstream
libstdc++-v3/include/std/streambuf
libstdc++-v3/include/std/string_view
libstdc++-v3/include/std/syncstream
libstdc++-v3/include/std/system_error

index a4fd25271c2d04b901cf75fbd283d5fa8f1c1e62..5e06fd378eab9430495cf6775b1efbffa56135c4 100644 (file)
@@ -39,7 +39,7 @@
 #include <bits/c++config.h>
 #include <bits/c++io.h>  // for __c_lock and __c_file
 #include <bits/move.h>   // for swap
-#include <ios>
+#include <bits/ios_base.h>     // For ios_base declarations.
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
index ec932181a96688dcb0a1a97c6233502a75208252..f91a93ae4aa6db131e70798382ff9572677f5865 100644 (file)
@@ -140,6 +140,11 @@ bits_freestanding = \
        ${bits_srcdir}/functional_hash.h \
        ${bits_srcdir}/intcmp.h \
        ${bits_srcdir}/invoke.h \
+       ${bits_srcdir}/iosfwd.h \
+       ${bits_srcdir}/iosfwd_file.h \
+       ${bits_srcdir}/iosfwd_span.h \
+       ${bits_srcdir}/iosfwd_string.h \
+       ${bits_srcdir}/iosfwd_sync.h \
        ${bits_srcdir}/iterator_concepts.h \
        ${bits_srcdir}/new_except.h \
        ${bits_srcdir}/new_throw.h \
index 00ae5209f60413aabcd34afb0ab3b0ecf1ddbf04..611ef30c6cdb6775809b82d8e50157f70d3c6392 100644 (file)
@@ -498,6 +498,11 @@ bits_freestanding = \
        ${bits_srcdir}/functional_hash.h \
        ${bits_srcdir}/intcmp.h \
        ${bits_srcdir}/invoke.h \
+       ${bits_srcdir}/iosfwd.h \
+       ${bits_srcdir}/iosfwd_file.h \
+       ${bits_srcdir}/iosfwd_span.h \
+       ${bits_srcdir}/iosfwd_string.h \
+       ${bits_srcdir}/iosfwd_sync.h \
        ${bits_srcdir}/iterator_concepts.h \
        ${bits_srcdir}/new_except.h \
        ${bits_srcdir}/new_throw.h \
index f0c8c47f0aed6bcd7eb62dfbb46c09767556b129..8d0078000294b5593ce5b7a261f3eddb33fc839b 100644 (file)
 
 #include <type_traits>
 #include <locale>
-#include <iosfwd>
 #include <iomanip>
 #include <codecvt>
 #include <string_view>
 #include <system_error>
+#include <bits/iosfwd.h>
 #include <bits/stl_algobase.h>
 #include <bits/stl_pair.h>
 #include <bits/locale_conv.h>
diff --git a/libstdc++-v3/include/bits/iosfwd.h b/libstdc++-v3/include/bits/iosfwd.h
new file mode 100644 (file)
index 0000000..5254827
--- /dev/null
@@ -0,0 +1,112 @@
+// <iosfwd> Forward declarations -*- C++ -*-
+
+// Copyright (C) 1997-2026 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/>.
+
+/** @file include/iosfwd
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{iosfwd}
+ */
+
+#ifndef _GLIBCXX_IOSFWD_H
+#define _GLIBCXX_IOSFWD_H 1
+
+#ifdef _GLIBCXX_SYSHDR
+#pragma GCC system_header
+#endif
+
+#include <bits/requires_hosted.h> // iostreams
+
+#include <bits/c++config.h>
+#include <bits/char_traits.h>  // For char_traits, streamoff, streamsize, fpos
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  /**
+   *  @addtogroup io
+   *  @{
+  */
+  class ios_base;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_ios;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_streambuf;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_istream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_ostream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_iostream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class istreambuf_iterator;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class ostreambuf_iterator;
+
+
+  /// Base class for @c char streams.
+  typedef basic_ios<char>              ios;
+
+  /// Base class for @c char buffers.
+  typedef basic_streambuf<char>        streambuf;
+
+  /// Base class for @c char input streams.
+  typedef basic_istream<char>          istream;
+
+  /// Base class for @c char output streams.
+  typedef basic_ostream<char>          ostream;
+
+  /// Base class for @c char mixed input and output streams.
+  typedef basic_iostream<char>                 iostream;
+
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+  /// Base class for @c wchar_t streams.
+  typedef basic_ios<wchar_t>           wios;
+
+  /// Base class for @c wchar_t buffers.
+  typedef basic_streambuf<wchar_t>     wstreambuf;
+
+  /// Base class for @c wchar_t input streams.
+  typedef basic_istream<wchar_t>       wistream;
+
+  /// Base class for @c wchar_t output streams.
+  typedef basic_ostream<wchar_t>       wostream;
+
+  /// Base class for @c wchar_t mixed input and output streams.
+  typedef basic_iostream<wchar_t>      wiostream;
+#endif
+
+  /** @}  */
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+
+#endif /* _GLIBCXX_IOSFWD_H */
diff --git a/libstdc++-v3/include/bits/iosfwd_file.h b/libstdc++-v3/include/bits/iosfwd_file.h
new file mode 100644 (file)
index 0000000..dc7359d
--- /dev/null
@@ -0,0 +1,91 @@
+// <iosfwd> Forward declarations for <fstream> -*- C++ -*-
+
+// Copyright (C) 1997-2026 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/>.
+
+/** @file include/bits/iosfwd_file.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{iosfwd}
+ */
+
+#ifndef _GLIBCXX_IOSFWD_FILE_H
+#define _GLIBCXX_IOSFWD_FILE_H 1
+
+#ifdef _GLIBCXX_SYSHDR
+#pragma GCC system_header
+#endif
+
+#include <bits/requires_hosted.h> // iostreams
+
+#include <bits/iosfwd.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  /**
+   *  @addtogroup io
+   *  @{
+  */
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_filebuf;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_ifstream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_ofstream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT> >
+    class basic_fstream;
+
+  /// Class for @c char file buffers.
+  typedef basic_filebuf<char>          filebuf;
+
+  /// Class for @c char input file streams.
+  typedef basic_ifstream<char>                 ifstream;
+
+  /// Class for @c char output file streams.
+  typedef basic_ofstream<char>                 ofstream;
+
+  /// Class for @c char mixed input and output file streams.
+  typedef basic_fstream<char>          fstream;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+    /// Class for @c wchar_t file buffers.
+  typedef basic_filebuf<wchar_t>       wfilebuf;
+
+  /// Class for @c wchar_t input file streams.
+  typedef basic_ifstream<wchar_t>      wifstream;
+
+  /// Class for @c wchar_t output file streams.
+  typedef basic_ofstream<wchar_t>      wofstream;
+
+  /// Class for @c wchar_t mixed input and output file streams.
+  typedef basic_fstream<wchar_t>       wfstream;
+#endif
+  /// @}
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+
+#endif /* _GLIBCXX_IOSFWD_FILE_H */
diff --git a/libstdc++-v3/include/bits/iosfwd_span.h b/libstdc++-v3/include/bits/iosfwd_span.h
new file mode 100644 (file)
index 0000000..13d998d
--- /dev/null
@@ -0,0 +1,78 @@
+// <iosfwd> Forward declarations for <spanstream> -*- C++ -*-
+
+// Copyright (C) 2022-2026 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/>.
+
+/** @file include/bits/iosfwd_span.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{iosfwd}
+ */
+
+#ifndef _GLIBCXX_IOSFWD_SPAN_H
+#define _GLIBCXX_IOSFWD_SPAN_H 1
+
+#ifdef _GLIBCXX_SYSHDR
+#pragma GCC system_header
+#endif
+
+#include <bits/requires_hosted.h> // iostreams
+
+#include <bits/version.h>
+
+#ifdef __glibcxx_spanstream // >= C++23
+#include <bits/iosfwd.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  /**
+   *  @addtogroup io
+   *  @{
+  */
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT>>
+    class basic_spanbuf;
+  template<typename _CharT, typename _Traits = char_traits<_CharT>>
+    class basic_ispanstream;
+  template<typename _CharT, typename _Traits = char_traits<_CharT>>
+    class basic_ospanstream;
+  template<typename _CharT, typename _Traits = char_traits<_CharT>>
+    class basic_spanstream;
+
+  using spanbuf     = basic_spanbuf<char>;
+  using ispanstream = basic_ispanstream<char>;
+  using ospanstream = basic_ospanstream<char>;
+  using spanstream  = basic_spanstream<char>;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+  using wspanbuf     = basic_spanbuf<wchar_t>;
+  using wispanstream = basic_ispanstream<wchar_t>;
+  using wospanstream = basic_ospanstream<wchar_t>;
+  using wspanstream  = basic_spanstream<wchar_t>;
+#endif
+  /// @}
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+#endif // C++23
+#endif /* _GLIBCXX_IOSFWD_SPAN_H */
diff --git a/libstdc++-v3/include/bits/iosfwd_string.h b/libstdc++-v3/include/bits/iosfwd_string.h
new file mode 100644 (file)
index 0000000..28daa10
--- /dev/null
@@ -0,0 +1,101 @@
+// <iosfwd> Forward declarations for <sstream> -*- C++ -*-
+
+// Copyright (C) 1997-2026 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/>.
+
+/** @file include/bits/iosfwd_string.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{iosfwd}
+ */
+
+#ifndef _GLIBCXX_IOSFWD_STRING_H
+#define _GLIBCXX_IOSFWD_STRING_H 1
+
+#ifdef _GLIBCXX_SYSHDR
+#pragma GCC system_header
+#endif
+
+#include <bits/requires_hosted.h> // iostreams
+
+#include <bits/iosfwd.h>
+#include <bits/stringfwd.h>    // For string forward declarations.
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  /**
+   *  @addtogroup io
+   *  @{
+  */
+
+_GLIBCXX_BEGIN_NAMESPACE_CXX11
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT>,
+           typename _Alloc = allocator<_CharT> >
+    class basic_stringbuf;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT>,
+          typename _Alloc = allocator<_CharT> >
+    class basic_istringstream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT>,
+          typename _Alloc = allocator<_CharT> >
+    class basic_ostringstream;
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT>,
+          typename _Alloc = allocator<_CharT> >
+    class basic_stringstream;
+
+_GLIBCXX_END_NAMESPACE_CXX11
+
+  /// Class for @c char memory buffers.
+  typedef basic_stringbuf<char>        stringbuf;
+
+  /// Class for @c char input memory streams.
+  typedef basic_istringstream<char>    istringstream;
+
+  /// Class for @c char output memory streams.
+  typedef basic_ostringstream<char>    ostringstream;
+
+  /// Class for @c char mixed input and output memory streams.
+  typedef basic_stringstream<char>     stringstream;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+  /// Class for @c wchar_t memory buffers.
+  typedef basic_stringbuf<wchar_t>     wstringbuf;
+
+  /// Class for @c wchar_t input memory streams.
+  typedef basic_istringstream<wchar_t>         wistringstream;
+
+  /// Class for @c wchar_t output memory streams.
+  typedef basic_ostringstream<wchar_t>         wostringstream;
+
+  /// Class for @c wchar_t mixed input and output memory streams.
+  typedef basic_stringstream<wchar_t>  wstringstream;
+#endif
+  /// @}
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+
+#endif /* _GLIBCXX_IOSFWD_STRING_H */
diff --git a/libstdc++-v3/include/bits/iosfwd_sync.h b/libstdc++-v3/include/bits/iosfwd_sync.h
new file mode 100644 (file)
index 0000000..9f5e994
--- /dev/null
@@ -0,0 +1,72 @@
+// <iosfwd> Forward declarations for <syncstream> -*- C++ -*-
+
+// Copyright (C) 2022-2026 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/>.
+
+/** @file include/bits/iosfwd_sync.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{iosfwd}
+ */
+
+#ifndef _GLIBCXX_IOSFWD_SYNC_H
+#define _GLIBCXX_IOSFWD_SYNC_H 1
+
+#ifdef _GLIBCXX_SYSHDR
+#pragma GCC system_header
+#endif
+
+#include <bits/requires_hosted.h> // iostreams
+
+#include <bits/version.h>
+
+#ifdef __glibcxx_syncbuf // >= C++20 && CXX11_ABI
+#include <bits/iosfwd.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  /**
+   *  @addtogroup io
+   *  @{
+  */
+
+  template<typename _CharT, typename _Traits = char_traits<_CharT>,
+          typename _Allocator = allocator<_CharT>>
+    class basic_syncbuf;
+  template<typename _CharT, typename _Traits = char_traits<_CharT>,
+          typename _Allocator = allocator<_CharT>>
+    class basic_osyncstream;
+
+  using syncbuf = basic_syncbuf<char>;
+  using osyncstream = basic_osyncstream<char>;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+  using wsyncbuf = basic_syncbuf<wchar_t>;
+  using wosyncstream = basic_osyncstream<wchar_t>;
+#endif
+  /// @}
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+#endif // __glibcxx_syncbuf
+#endif /* _GLIBCXX_IOSFWD_SYNC_H */
index ba6f6e694ff1fbd29f219baec12e7b4a43954083..902ba047b2650b4415fc284b38250f481cd5119d 100644 (file)
@@ -41,9 +41,7 @@
 #include <cwctype>     // For wctype_t
 #include <cctype>
 #include <bits/ctype_base.h>
-#include <iosfwd>
 #include <bits/ios_base.h>  // For ios_base, ios_base::iostate
-#include <streambuf>
 #include <bits/cpp_type_traits.h>
 #include <ext/type_traits.h>
 #include <ext/numeric_traits.h>
index 4e4836d523cc26ba88d8bd5cd9373e02da9c3e4b..dcab8b3310856bbbfa48139d3c2a213d7fbfc789 100644 (file)
@@ -40,7 +40,7 @@
 
 #include <bits/c++config.h>
 #include <bits/c++locale.h>  // Defines __c_locale, config-specific include
-#include <iosfwd>            // For ostreambuf_iterator, istreambuf_iterator
+#include <bits/iosfwd.h>     // For ostreambuf_iterator, istreambuf_iterator
 #include <cctype>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index 7c53b21bdb3dcb856966ea38e6523f84cf290a74..703ebf7890cdec4445a09ee40687141222239cc4 100644 (file)
 
 #include <bits/requires_hosted.h> // iostreams
 
-#include <ios>
+#include <bits/iosfwd.h>       // For declarations of default template args.
+#include <bits/char_traits.h>  // For char_traits, streamoff, streamsize, fpos
+#include <bits/localefwd.h>    // For class locale
+#include <bits/ios_base.h>     // For ios_base declarations.
+#include <streambuf>
+#include <bits/basic_ios.h>
 #include <bits/ostream_insert.h>
 
 # define __glibcxx_want_print
index 4e52a1d164cb21d044444c5b8a9c6f78e1598768..a512283502eaa8d2750ea5c98e825b376a15b229 100644 (file)
@@ -34,7 +34,7 @@
 #pragma GCC system_header
 #endif
 
-#include <iosfwd>
+#include <bits/iosfwd.h>
 #include <bits/cxxabi_forced.h>
 #include <bits/exception_defines.h>
 
index ada32d3d3cb91cdc0b099587da9829c1c9feb321..8be9aace1711d3f430aa70f38f68d597920abb08 100644 (file)
@@ -49,7 +49,7 @@
 #ifndef _SHARED_PTR_H
 #define _SHARED_PTR_H 1
 
-#include <iosfwd>                // std::basic_ostream
+#include <bits/iosfwd.h>                 // std::basic_ostream
 #include <bits/shared_ptr_base.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index 9e85ae2c6e2e2b3de461b610e55d68bfbce8e454..7e529897998fcb2e9798c39526c05199fdafe1e9 100644 (file)
@@ -37,7 +37,7 @@
 #if __cplusplus >= 201103L
 #include <bits/c++config.h>
 
-#include <iosfwd>              // std::basic_ostream
+#include <bits/iosfwd.h>       // std::basic_ostream
 #include <tuple>               // std::tuple
 #include <bits/functional_hash.h> // std::hash
 #include <bits/invoke.h>       // std::__invoke
index 54130026ec29e20c458058ca720141ddd9b3a1ec..74da499bc7dd8108b5fdb32c6cd77ae8df39464b 100644 (file)
@@ -34,7 +34,7 @@
 #pragma GCC system_header
 #endif
 
-#include <iosfwd>
+#include <bits/iosfwd.h>
 #include <bits/move.h>
 #include <bits/stl_iterator_base_types.h>
 #include <debug/debug.h>
index c4e222b8fefb8ca6b2f47be025fd8b0f2a5afdf1..653d417c6288c3f55b6f483bde7406c4c9bde982 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <istream>
 #include <ostream>
+#include <bits/iosfwd_file.h>
 #include <bits/codecvt.h>
 #include <cstdio>             // For BUFSIZ
 #include <bits/basic_file.h>  // For __basic_file, __c_lock
index 3841390b6335370197f1a2a8b86d1bc041bf5647..34a9edf178c4a03bcc922aca17bcfb59e9fe204c 100644 (file)
@@ -43,7 +43,7 @@
 #include <bits/requires_hosted.h> // iostreams
 
 #include <bits/c++config.h>
-#include <iosfwd>
+#include <bits/iosfwd.h>
 #include <bits/ios_base.h>
 
 #define __glibcxx_want_quoted_string_io
index 49f3aafd1de0b07915879d9fc80f707ede936a02..e9b1d6a165cd4121f30a69df539eb42e7ea1d363 100644 (file)
@@ -40,8 +40,6 @@
 #include <bits/requires_hosted.h> // iostreams
 
 #include <iosfwd>
-#include <exception>           // For ios_base::failure
-#include <bits/char_traits.h>  // For char_traits, streamoff, streamsize, fpos
 #include <bits/localefwd.h>    // For class locale
 #include <bits/ios_base.h>     // For ios_base declarations.
 #include <streambuf>
index 42124ad30df48ce6a9e9037b9340203025bf900c..1d5e684b53bb663628415fe018573dc5aa1b689a 100644 (file)
 
 #include <bits/requires_hosted.h> // iostreams
 
-#include <bits/c++config.h>
-#include <bits/stringfwd.h>    // For string forward declarations.
-#include <bits/postypes.h>
-
-namespace std _GLIBCXX_VISIBILITY(default)
-{
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
-
   /**
    *  @defgroup io I/O
    *
    *  Nearly all of the I/O classes are parameterized on the type of
-   *  characters they read and write.  (The major exception is ios_base at
+   *  characters they read and write.  (The major exception is `ios_base` at
    *  the top of the hierarchy.)  This is a change from pre-Standard
    *  streams, which were not templates.
    *
-   *  For ease of use and compatibility, all of the basic_* I/O-related
+   *  For ease of use and compatibility, all of the `basic_*` I/O-related
    *  classes are given typedef names for both of the builtin character
    *  widths (wide and narrow).  The typedefs are the same as the
    *  pre-Standard names, for example:
    *
-   *  @code
+   *  ```
    *     typedef basic_ifstream<char>  ifstream;
-   *  @endcode
+   *  ```
    *
    *  Because properly forward-declaring these classes can be difficult, you
-   *  should not do it yourself.  Instead, include the &lt;iosfwd&gt;
+   *  should not do it yourself.  Instead, include the `<iosfwd>`
    *  header, which contains only declarations of all the I/O classes as
    *  well as the typedefs.  Trying to forward-declare the typedefs
-   *  themselves (e.g., <code>class ostream;</code>) is not valid ISO C++.
+   *  themselves (e.g., `class ostream;`) is not valid ISO C++.
    *
    *  For more specific declarations, see
    *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/io.html#std.io.objects
-   *
-   *  @{
-  */
-  class ios_base;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_ios;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_streambuf;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_istream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_ostream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_iostream;
-
-
-_GLIBCXX_BEGIN_NAMESPACE_CXX11
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT>,
-           typename _Alloc = allocator<_CharT> >
-    class basic_stringbuf;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT>,
-          typename _Alloc = allocator<_CharT> >
-    class basic_istringstream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT>,
-          typename _Alloc = allocator<_CharT> >
-    class basic_ostringstream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT>,
-          typename _Alloc = allocator<_CharT> >
-    class basic_stringstream;
-
-_GLIBCXX_END_NAMESPACE_CXX11
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_filebuf;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_ifstream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_ofstream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class basic_fstream;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class istreambuf_iterator;
-
-  template<typename _CharT, typename _Traits = char_traits<_CharT> >
-    class ostreambuf_iterator;
-
-
-  /// Base class for @c char streams.
-  typedef basic_ios<char>              ios;
-
-  /// Base class for @c char buffers.
-  typedef basic_streambuf<char>        streambuf;
-
-  /// Base class for @c char input streams.
-  typedef basic_istream<char>          istream;
-
-  /// Base class for @c char output streams.
-  typedef basic_ostream<char>          ostream;
-
-  /// Base class for @c char mixed input and output streams.
-  typedef basic_iostream<char>                 iostream;
-
-  /// Class for @c char memory buffers.
-  typedef basic_stringbuf<char>        stringbuf;
-
-  /// Class for @c char input memory streams.
-  typedef basic_istringstream<char>    istringstream;
-
-  /// Class for @c char output memory streams.
-  typedef basic_ostringstream<char>    ostringstream;
-
-  /// Class for @c char mixed input and output memory streams.
-  typedef basic_stringstream<char>     stringstream;
-
-  /// Class for @c char file buffers.
-  typedef basic_filebuf<char>          filebuf;
-
-  /// Class for @c char input file streams.
-  typedef basic_ifstream<char>                 ifstream;
-
-  /// Class for @c char output file streams.
-  typedef basic_ofstream<char>                 ofstream;
-
-  /// Class for @c char mixed input and output file streams.
-  typedef basic_fstream<char>          fstream;
-
-#ifdef _GLIBCXX_USE_WCHAR_T
-  /// Base class for @c wchar_t streams.
-  typedef basic_ios<wchar_t>           wios;
-
-  /// Base class for @c wchar_t buffers.
-  typedef basic_streambuf<wchar_t>     wstreambuf;
-
-  /// Base class for @c wchar_t input streams.
-  typedef basic_istream<wchar_t>       wistream;
-
-  /// Base class for @c wchar_t output streams.
-  typedef basic_ostream<wchar_t>       wostream;
-
-  /// Base class for @c wchar_t mixed input and output streams.
-  typedef basic_iostream<wchar_t>      wiostream;
-
-  /// Class for @c wchar_t memory buffers.
-  typedef basic_stringbuf<wchar_t>     wstringbuf;
-
-  /// Class for @c wchar_t input memory streams.
-  typedef basic_istringstream<wchar_t>         wistringstream;
-
-  /// Class for @c wchar_t output memory streams.
-  typedef basic_ostringstream<wchar_t>         wostringstream;
-
-  /// Class for @c wchar_t mixed input and output memory streams.
-  typedef basic_stringstream<wchar_t>  wstringstream;
-
-  /// Class for @c wchar_t file buffers.
-  typedef basic_filebuf<wchar_t>       wfilebuf;
-
-  /// Class for @c wchar_t input file streams.
-  typedef basic_ifstream<wchar_t>      wifstream;
-
-  /// Class for @c wchar_t output file streams.
-  typedef basic_ofstream<wchar_t>      wofstream;
-
-  /// Class for @c wchar_t mixed input and output file streams.
-  typedef basic_fstream<wchar_t>       wfstream;
-#endif
-
-#if __cplusplus >= 202002L && _GLIBCXX_USE_CXX11_ABI
-  template<typename _CharT, typename _Traits = char_traits<_CharT>,
-           typename _Allocator = allocator<_CharT>>
-    class basic_syncbuf;
-  template<typename _CharT, typename _Traits = char_traits<_CharT>,
-           typename _Allocator = allocator<_CharT>>
-    class basic_osyncstream;
-
-  using syncbuf = basic_syncbuf<char>;
-  using osyncstream = basic_osyncstream<char>;
-
-#ifdef _GLIBCXX_USE_WCHAR_T
-  using wsyncbuf = basic_syncbuf<wchar_t>;
-  using wosyncstream = basic_osyncstream<wchar_t>;
-#endif
-#endif // C++20 && CXX11_ABI
-
-#if __cplusplus > 202002L
-  template<typename _CharT, typename _Traits = char_traits<_CharT>>
-    class basic_spanbuf;
-  template<typename _CharT, typename _Traits = char_traits<_CharT>>
-    class basic_ispanstream;
-  template<typename _CharT, typename _Traits = char_traits<_CharT>>
-    class basic_ospanstream;
-  template<typename _CharT, typename _Traits = char_traits<_CharT>>
-    class basic_spanstream;
-
-  using spanbuf     = basic_spanbuf<char>;
-  using ispanstream = basic_ispanstream<char>;
-  using ospanstream = basic_ospanstream<char>;
-  using spanstream  = basic_spanstream<char>;
-
-#ifdef _GLIBCXX_USE_WCHAR_T
-  using wspanbuf     = basic_spanbuf<wchar_t>;
-  using wispanstream = basic_ispanstream<wchar_t>;
-  using wospanstream = basic_ospanstream<wchar_t>;
-  using wspanstream  = basic_spanstream<wchar_t>;
-#endif
-#endif // C++23
-
-  /** @}  */
+   */
 
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace
+#include <bits/iosfwd_file.h>
+#include <bits/iosfwd_string.h>
+#include <bits/iosfwd_sync.h>
+#include <bits/iosfwd_span.h>
 
 #endif /* _GLIBCXX_IOSFWD */
index f4b5fd8683460f7698760f480534fa3396d48e02..4b97dd2951aea6453880307fe45aca21db28ea49 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <bits/requires_hosted.h> // iostreams
 
-#include <bits/c++config.h>
+#include <ios>
 #include <ostream>
 #include <istream>
 
index 6a982460a1dc211abdd9cde9a852fa2cee783d21..9b8474a0da8ddbe621020ccfe5a5fe3777f0a5e7 100644 (file)
 
 #include <bits/requires_hosted.h> // iostreams
 
-#include <ios>
+#include <bits/iosfwd.h>       // For declarations of default template args.
+#include <bits/char_traits.h>  // For char_traits, streamoff, streamsize, fpos
+#include <bits/localefwd.h>    // For class locale
+#include <bits/ios_base.h>     // For ios_base declarations.
+#include <streambuf>
+#include <bits/basic_ios.h>
+
 #include <ostream>
 
 #if __cplusplus > 202302L
index ebbd9be296eae4f4501aad7439888fcc02f4bde0..ad512764a852959b495879504909630cb74a6902 100644 (file)
@@ -46,7 +46,7 @@
 #include <cstdint> // For uint_fast32_t, uint_fast64_t, uint_least32_t
 #include <cstdlib>
 #include <string>
-#include <iosfwd>
+#include <bits/iosfwd.h>
 #include <limits>
 #include <debug/debug.h>
 #include <type_traits>
index fbb40ff1db26aab63fc790fec0a2cc299a731e00..fd2a446ddaa348e283bb993bcf9f1b06e0942df8 100644 (file)
@@ -43,6 +43,7 @@
 #include <streambuf>
 #include <istream>
 #include <ostream>
+#include <bits/iosfwd_span.h>
 #include <bits/ranges_base.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index 421c1f744b3d81f3919d92c37c30e39e97e1dfba..1c491e16458e6405125e7d33b7891503d04d9856 100644 (file)
@@ -42,6 +42,7 @@
 #include <istream>
 #include <ostream>
 
+#include <bits/iosfwd_string.h>
 #include <bits/alloc_traits.h> // allocator_traits, __allocator_like
 
 #define __glibcxx_want_sstream_from_string_view
index d6036bd5ddc4091372c351e50db9b51707753164..616e44f74a76e92ba4944a976611432b381b9c73 100644 (file)
@@ -40,7 +40,7 @@
 #include <bits/requires_hosted.h> // iostreams
 
 #include <bits/c++config.h>
-#include <iosfwd>
+#include <bits/iosfwd.h>
 #include <bits/localefwd.h>
 #include <bits/ios_base.h>
 #include <bits/cpp_type_traits.h>
index efbf432f112946a1bb712a2cd659e453e16b23e3..81b0011245b56c3baf2b6a859ee699b829b04390 100644 (file)
@@ -63,7 +63,7 @@
 #endif
 
 #if _GLIBCXX_HOSTED
-# include <iosfwd>
+# include <bits/iosfwd.h>
 # include <bits/ostream_insert.h>
 #endif
 
index 29a44ba1d7af6af17e5854caf75caeff34153cba..9cecd513e9a5f62c5fc37f86213de1559ae07a5a 100644 (file)
@@ -43,6 +43,7 @@
 #ifdef __cpp_lib_syncbuf // C++ >= 20 && HOSTED && CXX11ABI
 #include <sstream>
 
+#include <bits/iosfwd_sync.h>
 #include <bits/alloc_traits.h>
 #include <bits/allocator.h>
 #include <bits/std_mutex.h>
index 6fe63010e339e601fcc7fe426a9b9d3914756b73..6dbef5ed45dc3ea7f1388a17bff89a417fc2b552 100644 (file)
@@ -41,7 +41,7 @@
 
 #include <bits/c++config.h>
 #include <bits/error_constants.h>
-#include <iosfwd>
+#include <bits/iosfwd.h>
 #include <stdexcept>
 #if __cplusplus > 201703L
 # include <compare>