On 08/11/2017 08:23 AM, Andrzej Krzemieński wrote:
> Regarding dereferencing a pointer versus accessing the pointee, I can see
> the following relevant sections:
>
> [defns.access]: "access -- <execution-time action> to read or modify the
> value of an object"
> [intro.object]/1: "The constructs in a C++ program create, destroy, refer
> to, access, and manipulate objects." -- as though referring to an object
> was distinct from accessing it.
> [expr.ref] says that operator. and operator-> are used for "class member
> access" -- not dereferencing.
>
> This would seem to imply that dereferencing is not accessing the pointee?
I think that existing implementations need that evaluating E1->E2
performs an access of *E1, otherwise type-based aliasing analysis would
not be sound. And this means that *E1 itself accesses the object.
On the other hand, this rule greatly reduces the usefulness of mutexes
and atomics because you cannot embed them in the object to which they
synchronize access because the usual syntax to refer to members
introduces a data race (the entire object is accessed). It is possible
to work around this using offsetof and pointer arithmetic, but no
programmer does this.
To me, this looks like a defect in the language, but addressing it is
not easy.
Florian