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

bad example in P0593R6 [diff.cpp17] #3742

Closed
zygoloid opened this issue Feb 19, 2020 · 0 comments
Closed

bad example in P0593R6 [diff.cpp17] #3742

zygoloid opened this issue Feb 19, 2020 · 0 comments
Assignees

Comments

@zygoloid
Copy link
Member

P0593R6 adds this example to Annex C:

constexpr int f() {
  int a = 123;
  using T = int;
  a.~T();
  return a;  // undefined behavior; previously returned 123
}
static_assert(f() == 123);  // ill-formed; previously valid

... but the comments here are wrong: in C++17, pseudo-destruction expressions weren't permitted in constant evaluation at all. This can be fixed by using a runtime example instead of a compile-time one, such as:

int main() {
  int a = 123;
  using T = int;
  a.~T();
  return a;  // undefined behavior; previously returned 123
}
@zygoloid zygoloid self-assigned this Feb 20, 2020
zygoloid added a commit that referenced this issue Feb 20, 2020
Pseudo-destructors weren't permitted in constant expressions before
C++20.

Fixes #3742.
zygoloid added a commit that referenced this issue Feb 25, 2020
Pseudo-destructors weren't permitted in constant expressions before
C++20.

Fixes #3742.
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