On Tue, Oct 06, 2020 at 10:47:34AM +0200, Andreas Schwab wrote: > On Okt 06 2020, Jakub Jelinek via Gcc-patches wrote: > > > I mean, we could just use: > > size_t nbytes = sizeof (irange) + sizeof (tree) * 2 * num_pairs; > > irange *r = (irange *) obstack_alloc (&m_obstack, nbytes); > > return new (r) irange ((tree *) (r + 1), num_pairs); > > without any new type. > > Modulo proper alignment.
Sure, but irange's last element is tree * which is pointer to pointer, and we need here an array of tree, i.e. pointers. So, it would indeed break on a hypothetical host that has smaller struct X ** alignment than struct X * alignment. I'm not aware of any. One could add a static_assert to verify that (that alignof (irange) >= alignof (tree) and that sizeof (irange) % alignof (tree) == 0). Jakub