cplusplus / cplusplus/draft

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

Open
#5,486 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cwg not-editorial
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

[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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the definitions in [basic.lval] with the wording in [expr.compound], especially [expr.cond] and [expr.comma]. Determine whether the cited uses of “result” can be made consistent with the value-category rules, then update the affected draft wording; done means the clauses use “result” consistently without implying that a result is itself an expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, tex
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.