-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_members.hpp
82 lines (73 loc) · 2.51 KB
/
no_members.hpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include "main.hpp"
#ifndef __NO_MEMBERS__
#define __NO_MEMBERS__
/*
These are practically just namespaces. The main reason for including them
is that when they are not actually ever inherited unless they contain
a virtual function. Because of this, when they appear in a type_info structure
their reported offset is 0. Analyzers need to be able to determine if the
inherited class is just a namespace.
*/
namespace NoMembers {
class A {
public:
A() {}
~A() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }
friend ostream& operator<< (ostream& os, A& a){
os << "A size: " << sizeof(A) << endl;
return os;
}
};
class B {
public:
B() {}
~B() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }
friend ostream& operator<< (ostream& os, B& b){
os << "B size: " << sizeof(B) << endl;
return os;
}
};
class C : public A, public B {
public:
C() {}
~C() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }
friend ostream& operator<< (ostream& os, C& c){
os << "C size: " << sizeof(C) << endl;
// os << "super_A: " << offset_of_base<A, C>(c) << endl;
// os << "super_B: " << offset_of_base<B, C>(c) << endl;
return os;
}
};
class D : public virtual A, public virtual B {
public:
D() {}
~D() {}
ptrdiff_t offset_of(int &data) { return abs((ptrdiff_t)this - (ptrdiff_t)&data); }
friend ostream& operator<< (ostream& os, D& d){
os << "D size: " << sizeof(D) << endl;
// os << "super_B: " << offset_of_base<B, D>(d) << endl;
// os << "super_A: " << offset_of_base<A, D>(d) << endl;
return os;
}
};
// this forces the generation of typeinfo for C
class E : public virtual C {
};
static A a;
static B b;
static C c;
static D d;
static E e;
void print() {
//printTitle(" NoMembers ");
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d;
}
}
#endif // __NO_MEMBERS__