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

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

Open
languagelawyer opened this issue Feb 12, 2021 · 0 comments · May be fixed by #4495
Open

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

languagelawyer opened this issue Feb 12, 2021 · 0 comments · May be fixed by #4495
Assignees

Comments

@languagelawyer
Copy link
Contributor

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;)

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