This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Aliasing 'this' in a C++ constructor
On Fri, 18 May 2018, Nathan Sidwell wrote:
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) {}
It is tempting to think so, but I don't see any language to that effect.
C11 has this example:
void h(int n, int * restrict p, int * restrict q, int * restrict r)
{
int i;
for (i = 0; i < n; i++)
p[i] = q[i] + r[i];
}
h(100, a, b, b) --> valid (because no write)
We have https://gcc.gnu.org/bugzilla/show_bug.cgi?id=13962 about using
alias information to simplify pointer comparisons.
--
Marc Glisse