Boost logo

Boost :

Subject: Re: [boost] [beast] Formal review
From: Groke, Paul (paul.groke_at_[hidden])
Date: 2017-07-12 15:20:07


> From: Peter Dimov via Boost
> Sent: Mittwoch, 12. Juli 2017 16:55
>
> > 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.

Isn't that kind-of the same thing? The aliasing rules more or less say that you must only use some char variant or a type that's compatible with the most derived type of an object at that location (which implies that the object is alive). Or did I completely misinterpret the standard/fail to remember correctly?

> (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.)

That should be easy to solve by excluding the optimization on platforms where CHAR_BIT != 8 or SIZE_MAX != 256 * sizeof(size_t).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk