История изменений
Исправление dissident, (текущая версия) :
Я так понял, это какие-то подобные проблемы, какие имеют писатели законов и регуляций налогов. Второй ответ хорошо это объясняет:
The C++ standards contain an open issue that underlying representation of objects is not an «array» but a «sequence» of unsigned char objects. Still, everyone treats it as an array
Issue вот: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1701
Доказательство что pointer arithmetic safe вот (из того же ответа, я просто как попугай за ним повторяю): http://eel.is/c draft/expr.sizeof#2 а именно строка: When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element.
Т.е. проблема похоже в самом стандарте и объектной модели, к которой есть issue, требующий поправить саму объектную модель. Если я все правильно понял.
PS По поводу того что UB из-за alignment, из того же трэда:
You can do it with «old fashioned» malloc, which gives you a block of memory that fulfils the most restrictive alignment on the respective platform (e.g. that of a long long double)
и из другого ответа:
• **Is pointer arithmetic undefined behavior when used over memory returned by operator new()?**
Nope, as long as you respect the process' memory boundaries — from this point of view new basically works the same way as malloc, moreover, new actually calls malloc in the vast majority of implementations in order to acquire the required area.
Т.е. проблема в недопиленной объектной модели.
Могу и ошибаться.
PPS Вот с placement array new там действительно косяки потому что оно хочет больше места, чем выделенно было malloc/operator new.
Исходная версия dissident, :
Я так понял, это какие-то подобные проблемы, какие имеют писатели законов и регуляций налогов. Второй ответ хорошо это объясняет:
The C++ standards contain an open issue that underlying representation of objects is not an «array» but a «sequence» of unsigned char objects. Still, everyone treats it as an array
Issue вот: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1701
Доказательство что pointer arithmetic safe вот (из того же ответа, я просто как попугай за ним повторяю): http://eel.is/c draft/expr.sizeof#2 а именно строка: When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element.
Т.е. проблема похоже в самом стандарте и объектной модели, к которой есть issue, требующий поправить саму объектную модель. Если я все правильно понял.