Date
2022-02-18.07:47:23
Message id
5792

Content

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.