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

[expr.add]p4 seem to conflict with [expr.add]p7 #2299

Closed
languagelawyer opened this issue Aug 16, 2018 · 1 comment
Closed

[expr.add]p4 seem to conflict with [expr.add]p7 #2299

languagelawyer opened this issue Aug 16, 2018 · 1 comment
Assignees

Comments

@languagelawyer
Copy link
Contributor

p4 says:

If the expression P points to element x[i] of an array object x with n elements, the expressions P + J and J + P (where J has the value j) point to the (possibly-hypothetical) element x[i + j] if 0 ≤ i + j ≤ n; otherwise, the behavior is undefined.

Semicolon suggests that "otherwise" applies to the first clause of the compound sentence, to both preconditions: expression shall point to an element of an array object and the inequalities shall be satisfied. Therefore, if the first precondition is not met, the behavior is undefined.

But p7 allows adding the value 0 to a null pointer value, which, of course, does not point to an element of any array object.

@jensmaurer
Copy link
Member

p5 has a related problem: "When two pointers to elements of the same array object are subtracted, the type of the result is an implementation-defined signed integral type; ..." This makes the type of the result somehow conditional on the operands pointing to elements of the same array object (which is a runtime condition). That can't work.

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

No branches or pull requests

2 participants