This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Include <memory> from system.h (PR bootstrap/82610)
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Michael Matz <matz at suse dot de>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, David Malcolm <dmalcolm at redhat dot com>, Gerald Pfeifer <gerald at pfeifer dot com>, Pedro Alves <palves at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Trevor Saunders <tbsaunde+gcc at tbsaunde dot org>
- Date: Mon, 23 Oct 2017 16:17:33 +0100
- Subject: Re: [PATCH] Include <memory> from system.h (PR bootstrap/82610)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jwakely at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7FEDC61D0D
- References: <1508763498-38147-1-git-send-email-dmalcolm@redhat.com> <CAFiYyc3abk0689HBxNaVAes5A4papiPJBRsAPspk-j1j=KOD2w@mail.gmail.com> <1508768117.17132.18.camel@redhat.com> <51652D7F-D46C-4736-900A-6C76143A9210@gmail.com> <alpine.LSU.2.21.1710231654050.22495@wotan.suse.de>
On 23/10/17 17:07 +0200, Michael Matz wrote:
Hi,
On Mon, 23 Oct 2017, Richard Biener wrote:
I guess so. But we have to make gdb happy as well. It really depends how
much each TU grows with the extra (unneeded) include grows in C++11 and
C++04 mode.
The c++ headers unconditionally included from system.h, with:
% echo '#include <$name>' | g++-7 -E -x c++ - | wc -l
new: 3564
cstring: 533
utility: 3623
memory: 28066
That's using the -std=gnu++4 default for g++-7, and for that mode
the header *is* needed, to get the definition of std::unique_ptr.
For C++98 (when it isn't needed) that header is much smaller:
tmp$ echo '#include <memory>' | g++ -E -x c++ - | wc -l
28101
tmp$ echo '#include <memory>' | g++ -E -x c++ - -std=gnu++98 | wc -l
4267
(Because it doesn't contain std::unique_ptr and std::shared_ptr before
C++11).
compile time:
% echo -e '#include <$name>\nint i;' | time g++-7 -c -x c++ -
new: 0:00.06elapsed, 17060maxresident, 0major+3709minor
cstring: 0:00.03elapsed, 13524maxresident, 0major+3075minor
utility: 0:00.05elapsed, 16952maxresident, 0major+3776minor
memory: 0:00.25elapsed, 40356maxresident, 0major+9764minor
Hence, <memory> is not cheap at all, including it unconditionally from
system.h when it isn't actually used by many things doesn't seem a good
idea.
Ciao,
Michael.