cplusplus / cplusplus/draft

[conv.lval] doesn't specify the result for objects that are not accessed?

Open
#4,493 0 comments 2 reactions 1 assignee View on GitHub

@jensmaurer is already working on this.

Since Feb 12, 2021.

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

Description

From https://stackoverflow.com/questions/58479267/initialization-order-of-constant-initialized-variable-with-static-storage-durati @sdkrystian

To my understanding, nothing specifies what value b will have.

const int a = 42;
const int b = a;

Variable a is usable in constant expressions, so it is not ODR-used, so [conv.lval]/(2.2) apply:

2 When an lvalue-to-rvalue conversion is applied to an expression E, and either

  • (2.1) E is not potentially evaluated, or
  • (2.2) the evaluation of E results in the evaluation of a member Ex of the set of potential results of E, and Ex names a variable x that is not odr-used by Ex

the value contained in the referenced object is not accessed.

I think it means (and should say) the object is not accessed. But this is not the main concern. [conv.lval]/3, which says «The result of the conversion is determined according to the following rules», doesn't seem to cover the case when l-to-r conversion is applied to an evaluated expression denoting an object which is not accessed. I believe the bullet (3.3) saying «Otherwise, the object indicated by the glvalue is read ([defns.access]), and the value contained in the object is the prvalue result» can't apply in case the object is not accessed. Or the implied reading of (3.3) is that the part about access is just ignored for non-accessed objects?

(In case there is doubt that [conv.lval] is applied to a in const int b = a;, it can be replaced with const int b = a + 0;)

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.