P0332 implies array incompleteness is no longer "local"
After working on a patch to clang for P0332 (pull request with patch coming soon), the biggest issue I see with this proposal is that array incompleteness is no longer "local" (I don't have a better word for this, but it will become clear what I mean pretty soon). That is, you only have to look at the outermost extent to determine the completeness of an array type. Because of this, we can always say that an array type is:
- complete,
T[N], and we don't care about the extents ofT(if any) as long asTis a complete type. Thus we only have to store information about[N]with the type and we can treat everything else recursively. - incomplete,
T[], and we don't care about the extents ofT(if any) as long asTis a complete type.
Note that in both cases, we only have to examine one "layer" of the completeness of T, and zero layers of the extents.
Now consider the state of affairs under P0332. Given a type T[N],
- the type is complete if
Tis not an array type. - if
Tis an array type of the formU[M], we have to (recursively) examine the completeness ofU. - if
Tis an array of the formU[], we know thatT[N]is an incomplete type, but we still have to expand the definition of incomplete type to includeN(in addition to the extents, if any, ofU)
This would lead to some structural changes in the way array types are described in clang. It's not a deal-breaker by any means, but it's emblematic of why this is not a trivial change.
We need a taxonomy of incomplete types. The standard talks about incomplete types in many ways: cv void, incomplete class, array of unknown bound, incomplete type that cannot be completed, incompletely-defined object type, array of incomplete class type, incomplete non-void type, incomplete object type, incompletely defined class, etc.
The taxonomy rules may be well-defined and non-recursive.
An incomplete type is
-
cv
void -
incomplete class type :
class X; -
array of incomplete class type :
X[N] -
array of unknown bound :
T[]
The T of an array of unknown bound may be a complete type, incomplete class type, array of incomplete class type, or an array of unknown bound.
An array type T[N] is
-
a complete type if
Tis a complete type -
an array of incomplete class type if
Tis an incomplete class type or array of incomplete class type -
an array of unknown bound if
Tis an array of unknown bound