12 Jul
2017
12 Jul
'17
2:54 p.m.
Andrey Semashev wrote:
I think the best solution would be to mark size_t with __attribute__((__may_alias__)) and use it instead of plain size_t.
No, the problem with this code is (realistically speaking) not aliasing, it's object lifetime. I don't think that any compiler is so strict as to break it though; not yet, and maybe not ever. (There's another source of _technically UB_, padding bits and trap representations, but we can also reasonably assume that they don't mater nowadays. Incidentally, unsigned char is the best type with which to access object representations, although all three narrow character types (and now std::byte) work.)