On Fri, May 18, 2018 at 09:57:42AM -0400, Jason Merrill wrote:
> > But what is invalid on:
> > struct S { int foo (S *); int a; } s { 2 };
> > int S::foo (S *x)
> > {
> >   int b = this->a;
> >   x->a = 5;
> >   b += this->a;
> >   return b;
> > }
> > int main ()
> > {
> >   if (s.foo (&s) != 7)
> >     abort ();
> > }
> >
> > I think if you make this a restrict pointer, this will be miscompiled.
> 
> We're only talking about the 'this' pointer in a constructor, not a
> normal member function like foo.

Oops, sorry, missed that.
Make it then:

struct S { S (S *); int a; } s (&s);
S::S (S *s)
{
  this->a = 2;
  s->a = 3;
  if (this->a != 3)
    abort ();
}

Or is it invalid to dereference s before it has been constructed?

        Jakub

Reply via email to