gcc: C++ Volatiles

1 
1 7.1 When is a Volatile C++ Object Accessed?
1 ===========================================
1 
1 The C++ standard differs from the C standard in its treatment of
1 volatile objects.  It fails to specify what constitutes a volatile
1 access, except to say that C++ should behave in a similar manner to C
1 with respect to volatiles, where possible.  However, the different
1 lvalueness of expressions between C and C++ complicate the behavior.
11 G++ behaves the same as GCC for volatile access, ⇒Volatiles C
 Extensions, for a description of GCC's behavior.
1 
1  The C and C++ language specifications differ when an object is accessed
1 in a void context:
1 
1      volatile int *src = SOMEVALUE;
1      *src;
1 
1  The C++ standard specifies that such expressions do not undergo lvalue
1 to rvalue conversion, and that the type of the dereferenced object may
1 be incomplete.  The C++ standard does not specify explicitly that it is
1 lvalue to rvalue conversion that is responsible for causing an access.
1 There is reason to believe that it is, because otherwise certain simple
1 expressions become undefined.  However, because it would surprise most
1 programmers, G++ treats dereferencing a pointer to volatile object of
1 complete type as GCC would do for an equivalent type in C.  When the
1 object has incomplete type, G++ issues a warning; if you wish to force
1 an error, you must force a conversion to rvalue with, for instance, a
1 static cast.
1 
1  When using a reference to volatile, G++ does not treat equivalent
1 expressions as accesses to volatiles, but instead issues a warning that
1 no volatile is accessed.  The rationale for this is that otherwise it
1 becomes difficult to determine where volatile access occur, and not
1 possible to ignore the return value from functions returning volatile
1 references.  Again, if you wish to force a read, cast the reference to
1 an rvalue.
1 
1  G++ implements the same behavior as GCC does when assigning to a
1 volatile object--there is no reread of the assigned-to object, the
1 assigned rvalue is reused.  Note that in C++ assignment expressions are
1 lvalues, and if used as an lvalue, the volatile object is referred to.
1 For instance, VREF refers to VOBJ, as expected, in the following
1 example:
1 
1      volatile int vobj;
1      volatile int &vref = vobj = SOMETHING;
1