On Fri, 13 Dec 2024 at 13:45, Jonathan Wakely <jwak...@redhat.com> wrote:
>
> This adds <bits/ostream.h> so that other headers don't need to include
> all of <ostream>, which pulls in all of <format> since C++23 (for the
> std::print and std::println overloads in <ostream>). This new header
> allows the constrained operator<< in <bits/unique_ptr.h> to be defined
> without all of std::format being compiled.
>
> We could also replace <ostream> with <bits/ostream.h> in all of
> <istream>, <fstream>, <sstream>, and <spanstream>. That seems more
> likely to cause problems for users who might be expecting <sstream> to
> define std::endl, for example. Although the standard doesn't guarantee
> that, it is more reasonable than expecting <memory> to define it! We can
> look into making those changes for GCC 16.
>
> libstdc++-v3/ChangeLog:
>
>         * include/Makefile.am: Add new header.
>         * include/Makefile.in: Regenerate.
>         * include/bits/unique_ptr.h: Include bits/ostream.h instead of
>         ostream.
>         * include/std/ostream: Include new header.
>         * include/bits/ostream.h: New file.
> ---
>
> Tested x86_64-linux. Any objections?
>
>  libstdc++-v3/include/Makefile.am       |   1 +
>  libstdc++-v3/include/Makefile.in       |   1 +
>  libstdc++-v3/include/bits/ostream.h    | 817 +++++++++++++++++++++++++
>  libstdc++-v3/include/bits/unique_ptr.h |   2 +-
>  libstdc++-v3/include/std/ostream       | 763 +----------------------
>  5 files changed, 821 insertions(+), 763 deletions(-)
>  create mode 100644 libstdc++-v3/include/bits/ostream.h
>
> diff --git a/libstdc++-v3/include/Makefile.am 
> b/libstdc++-v3/include/Makefile.am
> index 6efd3cd5f1c..07f3f027c82 100644
> --- a/libstdc++-v3/include/Makefile.am
> +++ b/libstdc++-v3/include/Makefile.am
> @@ -135,6 +135,7 @@ bits_freestanding = \
>         ${bits_srcdir}/memoryfwd.h \
>         ${bits_srcdir}/monostate.h \
>         ${bits_srcdir}/move.h \
> +       ${bits_srcdir}/ostream.h \
>         ${bits_srcdir}/out_ptr.h \
>         ${bits_srcdir}/predefined_ops.h \
>         ${bits_srcdir}/parse_numbers.h \
> diff --git a/libstdc++-v3/include/Makefile.in 
> b/libstdc++-v3/include/Makefile.in
> index 3b5f93ce185..25fc5a27a2b 100644
> --- a/libstdc++-v3/include/Makefile.in
> +++ b/libstdc++-v3/include/Makefile.in
> @@ -490,6 +490,7 @@ bits_freestanding = \
>         ${bits_srcdir}/memoryfwd.h \
>         ${bits_srcdir}/monostate.h \
>         ${bits_srcdir}/move.h \
> +       ${bits_srcdir}/ostream.h \
>         ${bits_srcdir}/out_ptr.h \
>         ${bits_srcdir}/predefined_ops.h \
>         ${bits_srcdir}/parse_numbers.h \
> diff --git a/libstdc++-v3/include/bits/ostream.h 
> b/libstdc++-v3/include/bits/ostream.h
> new file mode 100644
> index 00000000000..b63b8dc51aa
> --- /dev/null
> +++ b/libstdc++-v3/include/bits/ostream.h
> @@ -0,0 +1,817 @@
> +// Output streams -*- C++ -*-
> +
> +// Copyright (C) 1997-2024 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 bits/ostream.h
> + *  This is an internal header file, included by other library headers.
> + *  Do not attempt to use it directly. @headername{ostream}
> + */
> +
> +//
> +// ISO C++ 14882: 27.6.2  Output streams
> +//
> +
> +#ifndef _GLIBCXX_OSTREAM_H
> +#define _GLIBCXX_OSTREAM_H 1
> +
> +#ifdef _GLIBCXX_SYSHDR
> +#pragma GCC system_header
> +#endif
> +
> +#include <bits/requires_hosted.h> // iostreams
> +
> +#include <ios>
> +#include <bits/ostream_insert.h>
> +#if __cplusplus > 202002L
> +# include <format>

It might help if I didn't copy&paste this include into the new header,
given that avoiding <format> is a large part of the rationale for this
change in the first place.

With that fixed, including <memory> in an empty C++23 TU produces
37kloc, compared to 55kloc before (as counted by the cloc utility).

Reply via email to