https://gcc.gnu.org/g:396ad1175450c22098a59a0e033dcdd5fc19b2ff
commit r17-806-g396ad1175450c22098a59a0e033dcdd5fc19b2ff Author: Jonathan Wakely <[email protected]> Date: Tue May 19 16:51:14 2026 +0100 libstdc++: Split <iosfwd> and only include it in <ios> [PR125371] 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 <[email protected]> Diff: --- libstdc++-v3/config/io/basic_file_stdio.h | 2 +- libstdc++-v3/include/Makefile.am | 5 + libstdc++-v3/include/Makefile.in | 5 + libstdc++-v3/include/bits/fs_path.h | 2 +- libstdc++-v3/include/bits/iosfwd.h | 112 +++++++++++++++ libstdc++-v3/include/bits/iosfwd_file.h | 91 ++++++++++++ libstdc++-v3/include/bits/iosfwd_span.h | 78 +++++++++++ libstdc++-v3/include/bits/iosfwd_string.h | 101 ++++++++++++++ libstdc++-v3/include/bits/iosfwd_sync.h | 72 ++++++++++ libstdc++-v3/include/bits/locale_facets.h | 2 - libstdc++-v3/include/bits/localefwd.h | 2 +- libstdc++-v3/include/bits/ostream.h | 7 +- libstdc++-v3/include/bits/ostream_insert.h | 2 +- libstdc++-v3/include/bits/shared_ptr.h | 2 +- libstdc++-v3/include/bits/std_thread.h | 2 +- libstdc++-v3/include/bits/stream_iterator.h | 2 +- libstdc++-v3/include/std/fstream | 1 + libstdc++-v3/include/std/iomanip | 2 +- libstdc++-v3/include/std/ios | 2 - libstdc++-v3/include/std/iosfwd | 208 ++-------------------------- libstdc++-v3/include/std/iostream | 2 +- libstdc++-v3/include/std/istream | 8 +- libstdc++-v3/include/std/random | 2 +- libstdc++-v3/include/std/spanstream | 1 + libstdc++-v3/include/std/sstream | 1 + libstdc++-v3/include/std/streambuf | 2 +- libstdc++-v3/include/std/string_view | 2 +- libstdc++-v3/include/std/syncstream | 1 + libstdc++-v3/include/std/system_error | 2 +- 29 files changed, 505 insertions(+), 216 deletions(-) diff --git a/libstdc++-v3/config/io/basic_file_stdio.h b/libstdc++-v3/config/io/basic_file_stdio.h index a4fd25271c2d..5e06fd378eab 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.h +++ b/libstdc++-v3/config/io/basic_file_stdio.h @@ -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) { diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index ec932181a966..f91a93ae4aa6 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -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 \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 00ae5209f604..611ef30c6cdb 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -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 \ diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index f0c8c47f0aed..8d0078000294 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -34,11 +34,11 @@ #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 index 000000000000..525482770b28 --- /dev/null +++ b/libstdc++-v3/include/bits/iosfwd.h @@ -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 index 000000000000..dc7359de02f7 --- /dev/null +++ b/libstdc++-v3/include/bits/iosfwd_file.h @@ -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 index 000000000000..13d998d477e4 --- /dev/null +++ b/libstdc++-v3/include/bits/iosfwd_span.h @@ -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 index 000000000000..28daa101d4ba --- /dev/null +++ b/libstdc++-v3/include/bits/iosfwd_string.h @@ -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 index 000000000000..9f5e9948e74a --- /dev/null +++ b/libstdc++-v3/include/bits/iosfwd_sync.h @@ -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 */ diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index ba6f6e694ff1..902ba047b265 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -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> diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h index 4e4836d523cc..dcab8b331085 100644 --- a/libstdc++-v3/include/bits/localefwd.h +++ b/libstdc++-v3/include/bits/localefwd.h @@ -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) diff --git a/libstdc++-v3/include/bits/ostream.h b/libstdc++-v3/include/bits/ostream.h index 7c53b21bdb3d..703ebf7890cd 100644 --- a/libstdc++-v3/include/bits/ostream.h +++ b/libstdc++-v3/include/bits/ostream.h @@ -40,7 +40,12 @@ #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 diff --git a/libstdc++-v3/include/bits/ostream_insert.h b/libstdc++-v3/include/bits/ostream_insert.h index 4e52a1d164cb..a512283502ea 100644 --- a/libstdc++-v3/include/bits/ostream_insert.h +++ b/libstdc++-v3/include/bits/ostream_insert.h @@ -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> diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index ada32d3d3cb9..8be9aace1711 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -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) diff --git a/libstdc++-v3/include/bits/std_thread.h b/libstdc++-v3/include/bits/std_thread.h index 9e85ae2c6e2e..7e529897998f 100644 --- a/libstdc++-v3/include/bits/std_thread.h +++ b/libstdc++-v3/include/bits/std_thread.h @@ -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 diff --git a/libstdc++-v3/include/bits/stream_iterator.h b/libstdc++-v3/include/bits/stream_iterator.h index 54130026ec29..74da499bc7dd 100644 --- a/libstdc++-v3/include/bits/stream_iterator.h +++ b/libstdc++-v3/include/bits/stream_iterator.h @@ -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> diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream index c4e222b8fefb..653d417c6288 100644 --- a/libstdc++-v3/include/std/fstream +++ b/libstdc++-v3/include/std/fstream @@ -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 diff --git a/libstdc++-v3/include/std/iomanip b/libstdc++-v3/include/std/iomanip index 3841390b6335..34a9edf178c4 100644 --- a/libstdc++-v3/include/std/iomanip +++ b/libstdc++-v3/include/std/iomanip @@ -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 diff --git a/libstdc++-v3/include/std/ios b/libstdc++-v3/include/std/ios index 49f3aafd1de0..e9b1d6a165cd 100644 --- a/libstdc++-v3/include/std/ios +++ b/libstdc++-v3/include/std/ios @@ -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> diff --git a/libstdc++-v3/include/std/iosfwd b/libstdc++-v3/include/std/iosfwd index 42124ad30df4..1d5e684b53bb 100644 --- a/libstdc++-v3/include/std/iosfwd +++ b/libstdc++-v3/include/std/iosfwd @@ -39,222 +39,36 @@ #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 <iosfwd> + * 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 */ diff --git a/libstdc++-v3/include/std/iostream b/libstdc++-v3/include/std/iostream index f4b5fd868346..4b97dd2951ae 100644 --- a/libstdc++-v3/include/std/iostream +++ b/libstdc++-v3/include/std/iostream @@ -39,7 +39,7 @@ #include <bits/requires_hosted.h> // iostreams -#include <bits/c++config.h> +#include <ios> #include <ostream> #include <istream> diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream index 6a982460a1dc..9b8474a0da8d 100644 --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -39,7 +39,13 @@ #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 diff --git a/libstdc++-v3/include/std/random b/libstdc++-v3/include/std/random index ebbd9be296ea..ad512764a852 100644 --- a/libstdc++-v3/include/std/random +++ b/libstdc++-v3/include/std/random @@ -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> diff --git a/libstdc++-v3/include/std/spanstream b/libstdc++-v3/include/std/spanstream index fbb40ff1db26..fd2a446ddaa3 100644 --- a/libstdc++-v3/include/std/spanstream +++ b/libstdc++-v3/include/std/spanstream @@ -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) diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index 421c1f744b3d..1c491e16458e 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -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 diff --git a/libstdc++-v3/include/std/streambuf b/libstdc++-v3/include/std/streambuf index d6036bd5ddc4..616e44f74a76 100644 --- a/libstdc++-v3/include/std/streambuf +++ b/libstdc++-v3/include/std/streambuf @@ -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> diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index efbf432f1129..81b0011245b5 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -63,7 +63,7 @@ #endif #if _GLIBCXX_HOSTED -# include <iosfwd> +# include <bits/iosfwd.h> # include <bits/ostream_insert.h> #endif diff --git a/libstdc++-v3/include/std/syncstream b/libstdc++-v3/include/std/syncstream index 29a44ba1d7af..9cecd513e9a5 100644 --- a/libstdc++-v3/include/std/syncstream +++ b/libstdc++-v3/include/std/syncstream @@ -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> diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 6fe63010e339..6dbef5ed45dc 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -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>
