https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125371
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <[email protected]>: 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]>
