Aliasing 'this' in a C++ constructor

Nathan Sidwell nathan@acm.org
Fri May 18 13:05:00 GMT 2018


On 05/18/2018 08:53 AM, Marc Glisse wrote:

> As long as you do not dereference ptr in the constructor, that shouldn't 
> contradict 'restrict'. The PR gives this quote from the standard:
> 
> "During the construction of an object, if the value of the object or any 
> of its subobjects is accessed through a glvalue that is not obtained, 
> directly or indirectly, from the constructor’s this pointer, the value 
> of the object or subobject thus obtained is unspecified."
> 
> which reads quite close to saying that 'this' is restrict.
Indeed it is, thanks.

what about comparisons to this?  I thought restrict implied such a 
comparison was 'never the same'?

ie. if the ctor was:
   selfie (selfie *ptr) : me (ptr==this ? 0 : ptr) {}

nathan

-- 
Nathan Sidwell



More information about the Gcc-patches mailing list