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

[basic.types.general] p6 Incorrect comment in example #4779

Closed
xmh0511 opened this issue Jul 26, 2021 · 1 comment · Fixed by #4783
Closed

[basic.types.general] p6 Incorrect comment in example #4779

xmh0511 opened this issue Jul 26, 2021 · 1 comment · Fixed by #4783
Assignees

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 26, 2021

[basic.types#general-example-3]

extern int arr[];               // the type of arr is incomplete
typedef int UNKA[];             // UNKA is an incomplete type
UNKA* arrp;                     // arrp is a pointer to an incomplete type
int  arr[10];                   // now the type of arr is complete
void bar() {
  arrp = &arr;                  // error: different types
}

The above example is a simplified example of [basic.types#general-example-3], the comment says it's an error. However, it's valid even though their types are different. A qualification conversion can be used to convert the type of &arr to the cv-unqualified type of arrp, which obeys [expr.ass#3]

If the right operand is an expression, it is implicitly converted to the cv-unqualified type of the left operand.

The type of &arr is pointer to array of 10 int whilst the type of arrp is pointer to array of unknown bound of int, as per [conv.qual#3], the former type can be converted to the later type by a qualification conversion. Hence, the comment should be "ok". GCC is in compliance with these rules.

@jensmaurer jensmaurer changed the title [Editorial] The comment is wrong in [basic.types#general-example-3] [basic.types.general] p6 Incorrect comment in example Jul 27, 2021
@jensmaurer
Copy link
Member

I think the assessment here is correct: An pointer to array of known bound can be converted to a pointer to an array of unknown bound.

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.

2 participants