devirtualize-virtual-function-calls.cpp [plain text]
struct A {
virtual void f();
virtual void f_const() const;
A h();
};
A g();
void f(A a, A *ap, A& ar) {
a.f();
ap->f();
ar.f();
A().f();
g().f();
a.h().f();
a.f_const();
(a).f();
}
struct B {
virtual void f();
~B();
B h();
};
void f() {
B().f();
B().h().f();
}
namespace test2 {
struct foo {
virtual void f();
virtual ~foo();
};
struct bar : public foo {
virtual void f();
virtual ~bar();
};
void f(bar *b) {
b->foo::f();
b->foo::~foo();
}
}
namespace test3 {
struct B {
};
struct D : public B {
};
void f(D d) {
d.B::~B();
}
}
namespace test4 {
struct Animal {
virtual void eat();
};
struct Fish : Animal {
virtual void eat();
};
struct Wrapper {
Fish fish;
};
extern Wrapper *p;
void test() {
p->fish.eat();
}
}