I have specific class hierarchy which crashes at runtime.(Visual Studio 2017)
struct A{};
struct B
{
auto f()
{
dynamic_cast<A *>(this);//triggers: Access violation
}
virtual ~B() = default;
};
struct C :virtual B, A//remove "virtual" to fix
{
C()
{
f();
}
int a;//remove to fix
};
struct D :virtual C{};//remove "virtual" to fix
int main()
{
D d;
}
Question is: Is this problem of code or rather compiler bug?
I tried a lots of variations, but none of them was satisfying, since this code looks correct for me.