Skip to content

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

Open

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.

Activity

  1. t3nsor commented on Mar 7, 2024

    @t3nsor

    I don't really see a defect here. If the expression is a prvalue, then the rule applies to the object that the prvalue tells you how to initialize.

    However, I'm not opposed to consolidating all the relevant wording in [dcl.array] and making it more precise, if someone volunteers to do that.

  2. t3nsor commented on Mar 7, 2024

    @t3nsor

    Incidentally, if someone does volunteer to do that, they might be able to tackle CWG1304 at the same time.

  3. frederick-vs-ja commented on Apr 1, 2024

    @frederick-vs-ja

    We have specified how to calculate the bound in [dcl.array] p7. I don't think the rule should be repeated for 3 times.

    It seems that the "declarator is followed by an initializer" part is problematic, as we don't want to limit the application of this rule to declarators.

    How about just saying "is initialized with an initializer" in [dcl.array] p7?

  4. changed the title [-][expr.type.conv] lacks the wording to specify the number of elements of an unknown bound array type[/-] [+]CWG3030 [expr.type.conv] lacks the wording to specify the number of elements of an unknown bound array type[/+] on May 11, 2025
  5. jensmaurer commented on May 11, 2025

    @jensmaurer
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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