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

Clarify wording of [class.eq] #6036

Open
leni536 opened this issue Dec 20, 2022 · 2 comments
Open

Clarify wording of [class.eq] #6036

leni536 opened this issue Dec 20, 2022 · 2 comments

Comments

@leni536
Copy link

leni536 commented Dec 20, 2022

Background

[class.eq] currently reads:

The return value V of a defaulted == operator function with parameters x and y is determined by comparing corresponding elements $x_i$ and $y_i$ in the expanded lists of subobjects for x and y (in increasing index order) until the first index $i$ where $x_i == y_i$ yields a result value which, when contextually converted to bool, yields false.
If no such index exists, V is true.
Otherwise, V is false.

The first long sentence describes the side effects of calling a defaulted operator==, while the other two sentences describe the return value.

This is unambiguous, but I think the wording could be improved.

Problem

At first glance this might be interpreted in a way that describes three distinct cases. In that case it's hard to make sense of the "Otherwise, V is false." sentence, as seemingly the previous sentences cover all cases.

This came up on the std-discussion mailing list: https://lists.isocpp.org/std-discussion/2022/12/1927.php

Some proposals for rewording

  1. Mirror the wording of [class.spaceship]:

...when contextually converted to bool, yields false;
V is false.
If no such index exists, V is true.

  1. Switch around the last two sentences:

..when contextually converted to bool, yields false.
If such index exists, V is false.
Otherwise, V is true.

Some other considerations

Even though the first long sentence describes the side effects of calling a defaulted operator==, it leads in with "The return value V of a defaulted == operator function with parameters x and y is determined...". It might be better to reword the first sentence in a way that doesn't mention the return value yet. One such wording would be, combined with the second suggestion above:

When a defaulted == operator function is called with parameters x and y then the corresponding elemnts $x_i$ and $y_i$ in the expanded lists of subobjects for x and y (in increasing index order) are compared until the first index $i$ where $x_i == y_i$ yields a result value which, when contextually converted to bool, yields false.
If such index exists, the return value is false.
Otherwise, the return value is true.

[class.spaceship] can have similar treatment.

@jwakely
Copy link
Member

jwakely commented Dec 20, 2022

See #6035

@leni536
Copy link
Author

leni536 commented Dec 20, 2022

See #6035

Thank you! This does modify the wording of the paragraphs in question, but I don't think it fully addresses the issue outlined here.

The PR simply removes V. It is an improvement though.

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