Skip to content

CWG3030 [expr.type.conv] lacks the wording to specify the number of elements of an unknown bound array type #509

@xmh0511

Description

@xmh0511

Full name of submitter (unless configured in github; will be published with the issue): Jim X

Consider this case:

int main(){ using type = int[]; type{1,2,3}; }

[dcl.array] p7 says:

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]).

The wording does not apply to this example because there is no declaration of an object, the expression is a prvalue. [dcl.init], [expr.new] specify how the array bound is calculated

[dcl.init.aggr] p10

An array of unknown bound initialized with a brace-enclosed initializer-list containing n initializer-clauses is defined as having n elements ([dcl.array]).

[expr.new] p7

If the type-id or new-type-id denotes an array type of unknown bound ([dcl.array]), the new-initializer shall not be omitted; the allocated object is an array with n elements, where n is determined from the number of initial elements supplied in the new-initializer ([dcl.init.aggr], [dcl.init.string]).

However, the nominated clause [expr.type.conv] in [dcl.array] does not describe how the array bound is calculated.

Suggested Resolution

Appending a similar wording in [expr.type.conv] p2

If the specified type is an array of an unknown bound, the initializer shall not be an empty braced-init-list {}, and the bound is determined by the number of elements of the initializer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions