From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ADCDA38582A2; Mon, 11 Jul 2022 11:00:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADCDA38582A2 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106241] compiler can't handle large array of strings Date: Mon, 11 Jul 2022 11:00:39 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: DUPLICATE 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jul 2022 11:00:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106241 --- Comment #7 from Jonathan Wakely --- (In reply to Robert Durkacz from comment #3) > So I guess the compiler just does not address this particular kind of use > case but it seems to me that, on the contrary, there should be a compilat= ion > capability to do this kind of thing. The problem is that "this kind of thing" is completely unreasonable. The element type of the array (Form_map) has a non-trivial destructor that need= s to deallocate the strings' memory. That means that the initializer for the arr= ay compiles to code like: try { form_array[0] =3D {"ADP", {"ADP", "s{NGDAILV}|mq_"}}; try { form_array[1] =3D {"ADP", {"ADP", "s{NGDAILV}|mq_"}}; try { form_array[2] =3D {"ADP", {"ADP", "s{NGDAILV}|mq_"}}; // ... 5.2 million more try-catch blocks } catch (...) { form_array[2].~Form_map(); throw; } } catch (...) { form_array[1].~Form_map(); throw; } } catch (...) { form_array[0].~Form_map(); throw; } The code to do that 5.2 million times is not easy to compile. And it's not really a sensible thing to try to compile. Just because all the construction and destruction is hidden inside std::string ctors and dtors doesn't make i= t a good idea. You're still asking for all that work to be done in a global initializer before main() even starts. Creating a trivial type that just holds a const char* is easy, there is no allocation, no non-trivial destructor, so no exceptions possible and so not= hing needs to be caught or rethrown.=