Created on 2025-03-09.00:00:00 last changed 6 months ago
(From submission #680.)
A specification is missing when a both a declaration of type "array of unknown bound of T" as well as one of the type "array of N T" is reachable. We should take the latter as the type.
Possible resolution:
Change in 6.9.1 [basic.types.general] paragraph 5 as follows:
A classthat has been declared but not definedtype in certain contexts (11.4.1 [class.mem.general]), an enumeration type in certain contexts (9.8.1 [dcl.enum]), or an array of unknown bound or of incomplete element type (9.3.4.5 [dcl.array]), is an incompletely-defined object type. [ Footnote: ... ] Incompletely-defined object types and cv void are incomplete types (6.9.2 [basic.fundamental]). [Note 2: Objects cannot be defined to have an incomplete type (6.2 [basic.def]). —end note]
Remove 6.9.1 [basic.types.general] paragraph 6:
A class type (such as “class X”) can be incomplete at one point in a translation unit and complete later on; the type “class X” is the same type at both points. The declared type of an array object can be an array of incomplete class type and therefore incomplete; if the class type is completed later on in the translation unit, the array type becomes complete; the array type at those two points is the same type. The declared type of an array object can be an array of unknown bound and therefore be incomplete at one point in a translation unit and complete later on; the array types at those two points (“array of unknown bound of T” and “array of N T”) are different types.
Change in 9.3.4.5 [dcl.array] paragraph 7 and 8 as follows:
An array type "array of N U" is complete at a program point P if U is complete at P, otherwise the array type is incomplete at P. A type "array of unknown bound of U" is incomplete.
In addition to declarations in which an incomplete object type is allowed, an array bound may be omitted in some cases in the declaration of a function parameter (9.3.4.6 [dcl.fct]). An array bound may also be omitted when an object (but not a non-static data member) of array type is initialized and the declarator is followed by an initializer (9.5 [dcl.init], 11.4 [class.mem], 7.6.1.4 [expr.type.conv], 7.6.2.8 [expr.new]). In these cases, the array bound is calculated from the number of initial elements (say, N) supplied (9.5.2 [dcl.init.aggr]), and the type of the array is “array of N U”.
Furthermore, if there is a reachable declaration of the entity that specifies a bound and has the same host scope (6.4.1 [basic.scope.scope]), an omitted array bound is taken to be the same as in that earlier declaration, and similarly for the definition of a static data member of a class.
If the declared type of a variable v is "array of unknown bound of U", its type is considered to be "array of N U" at any program point from which a declaration D of v is reachable (10.7 [module.reach]), where D specifies a bound N and has the same host scope (6.4.1 [basic.scope.scope]).
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-03-09 00:00:00 | admin | create |