Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dcl.array]/1 This grammar does not always declare an array. #2175

Closed
xskxzr opened this issue Jun 13, 2018 · 4 comments · Fixed by #2274
Closed

[dcl.array]/1 This grammar does not always declare an array. #2175

xskxzr opened this issue Jun 13, 2018 · 4 comments · Fixed by #2274
Assignees

Comments

@xskxzr
Copy link

xskxzr commented Jun 13, 2018

The issue is described in this StackOverflow question.

[dcl.array]/1 says "then the type of the identifier of D is an array type", but that's not true. For example, int (*p)[42]; is a pointer type but satisfies the grammar.

In addition, [dcl.array]/1 also says "T is called the array element type", which means, for example, int a[42][42];, the element type of a is int. I don't know if it is intended.

@jensmaurer
Copy link
Member

That was noticed in core issue 1222 as well, but the main topic (and thus the core issue) was rejected as NAD. Seems like a bug in the wording.

@jensmaurer jensmaurer added the cwg Issue must be reviewed by CWG. label Jun 13, 2018
@zygoloid
Copy link
Member

Yes, the "then the type of the identifier of D is an array type" part is nonsense. We could say "then the type of the identifier of D is an array type if the derived-declarator-type-list is empty", but I'd really prefer to omit that entirely.

The "T is called the array element type" part is not really wrong but not useful. This wording is only concerning the case where the [...] is the outermost part of the declarator, in which case T actually is the array element type. However, in a declaration in which we have a non-outermost array declarator chunk, such as:

int *p[42];

we are told to form the type of "int p[42]", then remove the "int" part and replace it with "pointer to int" (eg, "array of 42 int" -> "array of 42 pointer to int"), and the array element type of the resulting array type is never defined.

We also have no link between the type "array of N T" and the term "array type" from [basic.compound] other than the wrong statement "then the type of the identifier of D is an array type".

Perhaps we should define the canonical type strings in [basic.compound], move the definition of "array element type" there, and in [dcl.array] just specify how the canonical type string is formed.

@jensmaurer
Copy link
Member

jensmaurer commented Jun 14, 2018

@zygoloid, I'm unhappy with the larger change "Perhaps we should define the canonical type strings in [basic.compound]" done editorially, but do you think we can do a small localized fix editorially, or do we need CWG input for that?

@jensmaurer
Copy link
Member

Okay, I've tried a rewording of [dcl.array]. Looks much saner to me now.

@jensmaurer jensmaurer self-assigned this Jul 21, 2018
@jensmaurer jensmaurer removed the cwg Issue must be reviewed by CWG. label Jul 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants