C++: Respond to review comments.

This commit is contained in:
Mathias Vorreiter Pedersen
2020-11-13 10:44:06 +01:00
parent 5e1f36e7ff
commit b249777bfb
2 changed files with 30 additions and 30 deletions

View File

@@ -4,47 +4,47 @@ struct B;
void call_f(B*);
struct B : public A {
B() {
call_f(this);
}
B() {
call_f(this);
}
B(B& b) {
b.f(); // BAD: undefined behavior
}
B(B& b) {
b.f(); // BAD: undefined behavior
}
~B() {
f(); // BAD: undefined behavior
}
~B() {
f(); // BAD: undefined behavior
}
};
struct C : public B {
C(bool b) {
call_f(this);
C(bool b) {
call_f(this);
if(b) {
this->f(); // GOOD: Not a 'must' flow
}
}
if(b) {
this->f(); // GOOD: Not a 'must' flow
}
}
};
struct D : public B {
D() : B(*this) {}
D() : B(*this) {}
};
void call_f(B* x) {
x->f(); // 2 x BAD: Undefined behavior
x->f(); // 2 x BAD: Undefined behavior
}
struct E : public A {
E() {
f(); // GOOD: Will call `E::f`
}
E() {
f(); // GOOD: Will call `E::f`
}
void f() override {}
void f() override {}
};
struct F : public E {
F() {
((A*)this)->f(); // BAD: undefined behavior
}
F() {
((A*)this)->f(); // BAD: undefined behavior
}
};