#include <iostream>
struct V {
virtual void f() {
std::cout << "V" << std::endl;
}
};
struct A : virtual V {
virtual void f() {
std::cout << "A" << std::endl;
}
};
struct B : virtual V {
virtual void f() {
std::cout << "B" << std::endl;
}
B(V*, A*);
};
struct D : A, B {
virtual void f() {}
D() : B((A*)this, this) { }
};
B::B(V* v, A* a) {
a->f(); // undefined behavior, a’s type not a base of B
}
int main() {
D d;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IFYgewogIHZpcnR1YWwgdm9pZCBmKCkgewogICAgc3RkOjpjb3V0IDw8ICJWIiA8PCBzdGQ6OmVuZGw7CiAgfQp9OwoKc3RydWN0IEEgOiB2aXJ0dWFsIFYgewogIHZpcnR1YWwgdm9pZCBmKCkgewogICAgc3RkOjpjb3V0IDw8ICJBIiA8PCBzdGQ6OmVuZGw7CiAgfQp9OwoKc3RydWN0IEIgOiB2aXJ0dWFsIFYgewogdmlydHVhbCB2b2lkIGYoKSB7CiAgICBzdGQ6OmNvdXQgPDwgIkIiIDw8IHN0ZDo6ZW5kbDsKIH0KIEIoViosIEEqKTsKfTsKCnN0cnVjdCBEIDogQSwgQiB7CiAgdmlydHVhbCB2b2lkIGYoKSB7fQogIEQoKSA6IEIoKEEqKXRoaXMsIHRoaXMpIHsgfQp9OwoKQjo6QihWKiB2LCBBKiBhKSB7CiAgYS0+ZigpOyAvLyB1bmRlZmluZWQgYmVoYXZpb3IsIGHigJlzIHR5cGUgbm90IGEgYmFzZSBvZiBCCn0KCmludCBtYWluKCkgewogIEQgZDsKfQo=