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.spaceship]: Wording should be clearer that function pointers don't do <=> #3956

Closed
Dani-Hub opened this issue Apr 24, 2020 · 0 comments · Fixed by #3958
Closed

[expr.spaceship]: Wording should be clearer that function pointers don't do <=> #3956

Dani-Hub opened this issue Apr 24, 2020 · 0 comments · Fixed by #3958
Assignees

Comments

@Dani-Hub
Copy link
Member

[expr.spaceship] p7+8 use a convoluted and partially misleading way to exclude function pointers from three-way comparison:

7 If the composite pointer type is an object pointer type, p <=> q is of type std::strong_ordering. If
two pointer operands p and q compare equal (7.6.10), p <=> q yields std::strong_ordering::equal; if p
and q compare unequal, p <=> q yields std::strong_ordering::less if q compares greater than p and
std::strong_ordering::greater if p compares greater than q (7.6.9). Otherwise, the result is unspecified.
8 Otherwise, the program is ill-formed.

The first problem is that to me the "arm-length" of the first if in p7's first sentence is unclear and the second problem is that the end of p7 and the start of p8 are confusing. My initial reading lead to the understanding that the first p7 sentence is a very special sentence about object pointers and the following ones of that paragraph would apply to potentially other pointers as well.

I would therefore suggest to follow the style used in [expr.rel] p4 and reformulate p7 by converting it into a bullet list as follows:

7 If the composite pointer type is an object pointer type, p <=> q is of type std::strong_ordering and the result is defined in terms of the following rules:.

  • If two pointer operands p and q compare equal (7.6.10), p <=> q yields std::strong_ordering::equal;
  • otherwise, if p and q compare unequal, p <=> q yields std::strong_ordering::less if q compares greater than p and std::strong_ordering::greater if p compares greater than q (7.6.9).
  • Otherwise, the result is unspecified.

8 Otherwise, the program is ill-formed.

During a corresponding discussion with Richard on the CWG reflector he generally agreed with the suggested change direction and he suggested to additionally improve the previous p6 wording as well as follows:

6 If at least one of the operands is of object pointer type and the other operand is of object pointer or array type, array-to pointer conversions (7.3.2), pointer conversions (7.3.11), and qualification conversions (7.3.5) are performed on both operands to bring them to their composite pointer type (7.2.2). [..]

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