You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CWG3030 [expr.type.conv] lacks the wording to specify the number of elements of an unknown bound array type #509
Full name of submitter (unless configured in github; will be published with the issue): Jim X
Consider this case:
intmain(){
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.
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?
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
Activity
t3nsor commentedon Mar 7, 2024
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.
t3nsor commentedon Mar 7, 2024
Incidentally, if someone does volunteer to do that, they might be able to tackle CWG1304 at the same time.
frederick-vs-ja commentedon Apr 1, 2024
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?
[-][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[/+]jensmaurer commentedon May 11, 2025
CWG3030