Libstdc++: Split <iosfwd> and only include it in <ios> [PR125371]
Splits `<iosfwd>` into smaller headers and includes them selectively to avoid unnecessary forward declarations and improve compiler fix-it hints.
This commit addresses PR125371 by splitting the <iosfwd> header into smaller, more specific headers. It then includes these smaller headers only where needed, instead of including the entire <iosfwd> in headers like <istream> and <ostream>. This reduces the number of unnecessary forward declarations, which improves the accuracy of compiler fix-it hints for undeclared types and provides a better user experience when working with iostreams.
In Details
This change impacts header inclusion within the iostreams library. The issue stems from <ios> mandating inclusion of <iosfwd>, which declares all stream buffers and stream types. By splitting <iosfwd> and including it selectively, the change avoids forward-declaring std::stringbuf in <fstream>, which was preventing the compiler from suggesting #include <sstream> when std::istringstream was used without including the correct header. The <ios> header is now explicitly included in <iostream> to maintain standard compliance.
For Context
In C++, <iostream> provides input/output functionality. <iosfwd> contains forward declarations for all the stream classes (like std::cin, std::cout, std::ifstream), allowing them to be used without including the full definitions. This commit changes how these forward declarations are managed. By splitting <iosfwd> into smaller parts and including only the necessary parts in each header, the compiler can give more accurate suggestions when you forget to include a necessary header file.