When is reinterpret_cast UB?
03:31 19 Nov 2025

Does the code below contains UB?

struct A
{
    int x;
    char y;
};

int main()
{
    std::vector v(sizeof(A), 0);

    A* p = reinterpret_cast(v.data());

    p->x = 1;
    p->y = 'a';

    std::cout << p->x << " " << p->y << std::endl;
}

should I use std::launder?

c++ c++20