This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 113d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-03-20


2195. Unsolicited reading of trailing volatile members

Section: 9.2.9.2  [dcl.type.cv]     Status: open     Submitter: Hubert Tong     Date: 2015-11-06

Consider:

  struct A {
    ~A();
    double d;
    float f;
  };

  struct B : A { volatile int i; };

  A foo(B *bp) { return *static_cast<A *>(bp); }

Is it okay for the memory associated with bp->i to be accessed by foo?

See also 9.2.9.2 [dcl.type.cv] paragraph 5

The semantics of an access through a volatile glvalue are implementation-defined. If an attempt is made to access an object defined with a volatile-qualified type through the use of a non-volatile glvalue, the behavior is undefined.

Additional notes from the November, 2016 meeting:

See also national body comment CH2, addressed in March, 2017 by P0612R0.