[Bug c++/82899] *this in constructors could not alias with reference input parameters of the same type
antoshkka at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu May 3 17:47:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82899
--- Comment #8 from Antony Polukhin <antoshkka at gmail dot com> ---
(In reply to Richard Biener from comment #4)
> (In reply to Antony Polukhin from comment #2)
> > Looks like [class.ctor] paragraph 14 covers this case:
> >
> > "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."
>
> Yeah, sounds like covering this case. Thus we can make 'this' restrict in
> constructors (and possibly assignment operators if self-assignment is
> forbidden).
Self assignment is tricky and is OK to alias in most cases. It could be
restricted at some point after the `this != &rhs` check (as proposed in Bug
82918).
I'd rather start by "restricting this" for copy and move constructors, leaving
assignment as is.
More information about the Gcc-bugs
mailing list