Consider the program
#include<iostream>
struct A {
};
struct B {
void f() { std::cout << "Hello world!\n"; };
};
static_assert(alignof(A) == alignof(B));
int main() {
A a;
reinterpret_cast<B*>(&a)->f();
};
Note that the value of a
is never read or modified in the sense of the aliasing rule, as far as I can tell.
I am pretty sure that the above has undefined behavior, because I am trying to call f
on an object of wrong type. But what passage in the standard actually says that?