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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Not a dup, because turning {0, 0} into {} is still wrong even for trivial
classes:

struct X {
  X() = default;
  X(int n) : n(n+1) { }
  int n;
};
static_assert(__is_trivial(X), "");

int main()
{
  X x[1] { 1 };  // OK
  if (x->n != 2)
    __builtin_abort();

  X y[1] { 0 };
  if (y->n != 1)
    __builtin_abort();
}

Aborted (core dumped)


The array element has a non-empty initializer, so must call the X(int)
constructor, which has very different semantics from the default constructor.

An {0} initializer could be a null pointer constant too:

struct X {
  X() = default;
  X(int* p) : p(p ? p : new int(1)) { }
  int* p;
};
static_assert(__is_trivial(X), "");

int main()
{
  X x[1] { nullptr };  // OK
  if (*x->p != 1)
    __builtin_abort();

  X y[1] { 0 };
  if (*y->p != 1)
    __builtin_abort();
}

Segmentation fault (core dumped)

Reply via email to