https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121685

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> Note that LLVM happily hoists this load, creating wrong-code.

So LLVM does a load here?

std::vector<int> v; // size == 0
alignas(std::vector<int>) char c;
fun(v, reinterpret_cast<std::vector<int>&>(c));

Looking at the wording for reinterpret_cast I'm not actually sure if that cast
is valid, because the reinterpret_cast<T&>(x) is defined in terms of
*reinterpret_cast<T*>(&x) and the indirection with * would be undefined. So
maybe we can assume that doesn't happen.

For this case:

std::vector<int> v; // size == 0
auto ptr = new std::vector<int>;
auto& ref = *ptr;
delete ptr;
fun(v, ref);

I think the call is UB because we need to bind the m_mcowner reference
parameter to the object that ref refers to, but there is no such object now.

But I'm not confident about either of those, so CC jason for clarification.

Reply via email to