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

--- Comment #2 from Jens Maurer <jens.maurer at gmx dot net> ---
The whole point of flexible array members seems to be to save an allocation for
the array, with the precondition that the array size can be determined at
initialization time and stays fixed for the entire lifetime of the enclosing
struct.  In that scenario, I need to placement-new the array elements (or,
probably, the entire array) anyway, so requiring to explicitly call the
destructor(s) seems a natural duality.

In the example
    S s = { 3, { 1, 2, 3 } };
it seems surprising that the destructor for the elements is not called, given
that the number of elements is "right there" in the source code. [Yes, I have
an idea about the implementation difficulties here.] I'd rather prefer this
initialization example to be ill-formed, if the element type has a non-trivial
destructor.  Consider if the element type is a std::string (with dynamic
allocation) and this is inside a loop; this seems to cause a serious memory
leak.

Reply via email to