Open tbaederr opened 2 weeks ago
@llvm/issue-subscribers-clang-frontend
Author: Timm Baeder (tbaederr)
This might actually work just fine. The note is being emitted when k
is being destroyed at the end of the scope, where its lifetime has already ended when it was destroyed by the pseudo dtor expr.
So is clang correct here or the other compilers?
Looks like MSVC simply ignores the pseudo destructor while GCC makes the most sense to me: https://godbolt.org/z/71E33dvxW
The title seems wrong. Clang accepts such use when one uses std::construct_at
to resurrect k
(demo). So, it turns out that Clang correctly destroys k
but considers double destruction of a scalar object to be UB.
The current standard wording seemingly implies that double destruction of a scalar object is not UB and such repeated destruction has no effect. It's totally unclear to me whether this is intended, and I attempted to submit a CWG issue for this (cplusplus/CWG#361).
CC @zygoloid @jensmaurer
The title seems wrong. Clang accepts such use when one uses
std::construct_at
to resurrectk
(demo). So, it turns out that Clang correctly destroysk
but considers double destruction of a scalar object to be UB.The current standard wording seemingly implies that double destruction of a scalar object is not UB and such repeated destruction has no effect. It's totally unclear to me whether this is intended, and I attempted to submit a CWG issue for this (cplusplus/CWG#361).
CC @zygoloid @jensmaurer
I am almost sure we had a recent issue related to this and IIRC the consensus was double destruction is UB.
This code:
should probably work, GCC and MSVC accept it: https://godbolt.org/z/MavW6o7ox
And clang's diagnostic seem bogus: