fuchsia-virtual-inheritance.cpp
909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// RUN: %check_clang_tidy %s fuchsia-virtual-inheritance %t
class A {
public:
A(int value) : val(value) {}
int do_A() { return val; }
private:
int val;
};
class B : public virtual A {
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: direct virtual inheritance is disallowed [fuchsia-virtual-inheritance]
// CHECK-NEXT: class B : public virtual A {
public:
B() : A(0) {}
int do_B() { return 1 + do_A(); }
};
class C : public virtual A {
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: direct virtual inheritance is disallowed [fuchsia-virtual-inheritance]
// CHECK-NEXT: class C : public virtual A {
public:
C() : A(0) {}
int do_C() { return 2 + do_A(); }
};
class D : public B, public C {
public:
D(int value) : A(value), B(), C() {}
int do_D() { return do_A() + do_B() + do_C(); }
};
int main() {
A *a = new A(0);
B *b = new B();
C *c = new C();
D *d = new D(0);
return 0;
}