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

The result of an expression is given different meanings between [basic.lval] and [expr.compound] #5486

Open
xmh0511 opened this issue May 23, 2022 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented May 23, 2022

[basic.lval] p5 clearly defines the result of an expression, that is

The result of a glvalue is the entity denoted by the expression. The result of a prvalue is the value that the expression stores into its context; a prvalue that has type cv void has no result.

An expression is either a glvalue or a prvalue. The result of an expression is an object or function if the expression is glvalue or the value of a prvalue otherwise. However, in [expr.compound], we do not give such wording a consistent meaning. Such as [expr.cond] p1

It is evaluated and if it is true, the result of the conditional expression is the value of the second expression, otherwise that of the third expression.

the conditional expression is either a glvalue or a prvalue, the result of it is an object or function if it's a glvalue, or the value if it's a prvalue.

[expr.cond] p5

If the second and third operands are glvalues of the same value category and have the same type, the result is of that type and value category and it is a bit-field if the second or the third operand is a bit-field, or if both are bit-fields.

Saying that the result is a bit-field conforms to the definition of the result of a glvalue; a bit-field is an entity, it has no problem. However, saying that the result is of that type and value category seems to imply that the "result" means an expression, only expressions can have a value category. It is contradictory.

Such as [expr.comma] p1

The type and value of the result are the type and value of the right operand; the result is of the same value category as its right operand, and is a bit-field if its right operand is a bit-field.

Again, the comma expression is either a glvalue or prvalue. If it is a glvalue, the result of the comma expression is an entity per [basic.lval] p5, otherwise the value of the prvalue. We can see the first part and the second part of [expr.comma] p1 implies the result different meaning.

the result is of the same value category as its right operand

In this wording, The "result" is viewed as an expression.

is a bit-field if its right operand is a bit-field.

While in this wording, the "result" has the same definition as [basic.lval] p5 says. I just list the part of [expr.compound], the result of the expression has a different meaning, as above pointed, in its subclasses. It is better to say

The expression has the same value category, type, and result as that of E.

E for example is the second or third operand, the updated operand, or so on.

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

1 participant