https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106241

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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 compilation
> 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 needs to
deallocate the strings' memory. That means that the initializer for the array
compiles to code like:

try {
  form_array[0] = {"ADP", {"ADP", "s{NGDAILV}|mq_"}};
  try {
    form_array[1] = {"ADP", {"ADP", "s{NGDAILV}|mq_"}};
    try {
      form_array[2] = {"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 it 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 nothing
needs to be caught or rethrown.

Reply via email to