[try Beta version]
Not logged in

 
Should the subscript "opt" be dropped in the definition of "array of N T" in the standard?

Jan 10, 2025 at 9:54am
This is the definitive syntax of "array of N T" in C++ Standard https://eel.is/c++draft/dcl.array#1 :
D1 [ constant-expression_opt ] ...

I think the subscript "opt" should not be there for two reasons:

1) The descriptions of the item seem to assume that "constant-expression" cannot be omitted. If the bracket is empty, the descriptions would make no sense.

2) If "constant-expression" is omitted, the item 1 would be reduced to item 2. There is no need to take out this special case as a separate item.

Am I right?
Jan 10, 2025 at 11:17am
I think you might be right. It seems like a left-over from C++17 where it used one form to describe both cases, with and without constant expression. https://timsong-cpp.github.io/cppwp/n4659/dcl.array#1
Last edited on Jan 10, 2025 at 11:17am
Jan 10, 2025 at 11:46am
Thank you!
Jan 20, 2025 at 12:03pm
Hi

Is it because the array bound may be omitted when there are initialisers? The compiler counts all the initialisers and that is the array bound.
This is clause 7 from the same section, emphasis mine:

7. 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 ([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 ([dcl.init], [class.mem], [expr.type.conv], [expr.new]).
In these cases, the array bound is calculated from the number of initial elements (say, N) supplied ([dcl.init.aggr]), and the type of the array is “array of N U”.
Topic archived. No new replies allowed.