From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E868E3949090; Mon, 5 Dec 2022 20:50:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E868E3949090 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670273457; bh=V5bIC5vvx3AYwGlV6yth2DwxQk/yNnkC44hFxTWACMs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZeahU0Wn5PVQXThAV/bLXmm30lNELJiqcjiCgGjzEacgIJQkFZ6qn/4787STQ0Uth mLTsiPWa8ANe4fyy1bMY6b/GQC9I20RIv1wPnruG71a3nKf6WqZcYCAFJVq/8Yn8Tl XuZybwy7cn+sfFkqwRNmoxrxoTsJHVDA5pbekQ2o= From: "jason at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105838] [10/11/12/13 Regression] g++ 12.1.0 runs out of memory or time when building const std::vector of std::strings Date: Mon, 05 Dec 2022 20:50:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: compile-time-hog, memory-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: jason at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105838 --- Comment #12 from Jason Merrill --- Another significant part of the problem is that vector doesn't have= a generic initializer_list constructor. Adding template _GLIBCXX20_CONSTEXPR vector(initializer_list<__elt> __l, const allocator_type& __a =3D allocator_type()) : _Base(__a) { _M_range_initialize(__l.begin(), __l.end(), random_access_iterator_tag()); } so that it can construct from initializer_list makes the construction into a simple loop over a static array. Users can do this optimization manually by writing e.g. auto init =3D { "aahing", "aaliis", "aarrgh", "abacas", "abacus", "abakas", "abamps", "abands", "abased", "abaser", "abases", "abasia", }; const std::vector lst (init.begin(), init.end()); and so using the (template) iterator constructor instead of the (non-templa= te) initializer_list constructor. But that shouldn't be necessary. Jonathan, has anyone suggested adding generic init_list constructors to the container classes? What do you think about doing the above translation in the compiler? Is the compiler allowed to do that?=