История изменений
Исправление
pavlick,
(текущая версия)
:
А откуда указатель buf берется? Массив ведь расти будет не new T[capa]; Может и так про std::launder, а может нет:
// Case 3: access to a new object whose storage is provided by a byte array through
// a pointer to the array.
alignas(Y) std::byte s[sizeof(Y)];
Y* q = new(&s) Y{2};
const int f = reinterpret_cast<Y*>(&s)->z; // Class member access is undefined behavior:
// reinterpret_cast<Y*>(&s) has value
// "pointer to s" and does not
// point to a Y object
const int g = q->z; // OK
const int h = std::launder(reinterpret_cast<Y*>(&s))->z; // OK
Исходная версия
pavlick,
:
А откуда указатель buf берется? Массив ведь расти будет не new T[capa]; Может и так знаешь, а может нет:
// Case 3: access to a new object whose storage is provided by a byte array through
// a pointer to the array.
alignas(Y) std::byte s[sizeof(Y)];
Y* q = new(&s) Y{2};
const int f = reinterpret_cast<Y*>(&s)->z; // Class member access is undefined behavior:
// reinterpret_cast<Y*>(&s) has value
// "pointer to s" and does not
// point to a Y object
const int g = q->z; // OK
const int h = std::launder(reinterpret_cast<Y*>(&s))->z; // OK