From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 74C463858C74; Thu, 8 Jun 2023 15:01:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74C463858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686236474; bh=7izaZ39HPwRQfnCm6iablcLYIqJCIYf/GTS3jZOhk8U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KOvEtE5O/2V+00ViBcwg+4Ls1BoeZY9aib7S8eUnCpRLzp17Tag9MJs7oBUDZIR6d j/yxBXpU5UHU+m6lEAgr5U1bQK6djeDkv3riyuN5dslixzrAXcezGZOa7Ct01vpr9q GL65ZH2B21ID2+xvls5De6ZBR/Q+fd0xpEP24uxc= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110167] excessive compile time when optimizing std::to_array Date: Thu, 08 Jun 2023 15:01:14 +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: 13.1.0 X-Bugzilla-Keywords: compile-time-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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=3D110167 --- Comment #6 from Jonathan Wakely --- The bottom line, however, is that this use of std::to_array is not really reasonable. You're asking the compiler to create a variadic pack of 262144 integers, and then create a pack expansion for std::array{arr[i]...} where i= ... has 262144 elements in the pack. That's going to be insanely large. Maybe we can do this though: template [[nodiscard]] constexpr array, _Nm> to_array(_Tp (&__a)[_Nm]) noexcept(is_nothrow_constructible_v<_Tp, _Tp&>) { static_assert(!is_array_v<_Tp>); static_assert(is_constructible_v<_Tp, _Tp&>); if constexpr (_Nm > 1024 && is_trivially_default_constructible_v<_Tp> && is_trivially_assignable_v<_Tp&, _Tp&>) { array<_Tp, _Nm> __arr; for (size_t __i =3D 0; __i < _Nm; ++i) __arr[__i] =3D __a[__i]; return __arr; } else if constexpr (is_constructible_v<_Tp, _Tp&>) return [&__a](index_sequence<_Idx...>) { return array, _Nm>{{ __a[_Idx]... }}; }(make_index_sequence<_Nm>{}); __builtin_unreachable(); // FIXME: see PR c++/91388 }=