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

Example "uninit" in [dcl.constexpr] no longer valid #5718

Open
tkoeppe opened this issue Aug 7, 2022 · 2 comments · May be fixed by #6484
Open

Example "uninit" in [dcl.constexpr] no longer valid #5718

tkoeppe opened this issue Aug 7, 2022 · 2 comments · May be fixed by #6484

Comments

@tkoeppe
Copy link
Contributor

tkoeppe commented Aug 7, 2022

We discovered during the application of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2448r2.html (which removes one incorrect example) that there is another incorrect example in dcl.constexpr, Example 2 in (3.4):

constexpr int uninit() {
  struct { int a; } s;
  return s.a;                   // error: uninitialized read of s.a
}

@zygoloid says, "Yeah, it's an uninitialized read, but prior to p2448r2 that was IFNDR and now it's simply valid."

@JohelEGP
Copy link
Contributor

JohelEGP commented Aug 7, 2022

Now it's an error only during constant evaluation: https://godbolt.org/z/4Wz11ahWv

constexpr int uninit() {
  struct { int a; } s;
-  return s.a;                   // error: uninitialized read of s.a
+  return s.a;
}
+int x = uninit();
+constexpr int y = uninit();     // error: uninitialized read of s.a

I'm not sure what the initialization of x is.

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Aug 7, 2022

Another point @zygoloid made was that the // OK examples in this subclause are becoming increasingly less useful, as more and more constructions involving constant expressions are now OK. Maybe some pruning is in order.

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