forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MethodCalls.C
93 lines (81 loc) · 2.63 KB
/
MethodCalls.C
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
83
84
85
86
87
88
89
90
91
92
93
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
// RUN: cat %s | %cling -Xclang -verify
// XFAIL: powerpc64
// This test verifies that we get nice warning if a method on null ptr object is
// called.
extern "C" int printf(const char* fmt, ...);
class MyClass {
private:
int a;
public:
MyClass() : a(1){}
int getA(){return a;}
};
MyClass* my = 0;
my->getA() // expected-warning {{null passed to a callee that requires a non-null argument}}
struct AggregatedNull {
MyClass* m;
AggregatedNull() : m(0) {}
}
AggregatedNull agrNull;
agrNull.m->getA(); // expected-warning {{null passed to a callee that requires a non-null argument}}
class Left {
int m_LeftValue;
public:
Left() : m_LeftValue(-1) {}
int getLeftValue() { return m_LeftValue; }
void setLeftValue(int v) { m_LeftValue = v; }
};
class Right {
int m_RightValue;
public:
Right() : m_RightValue(-2) {}
int getRightValue() { return m_RightValue; }
void setRightValue(int v) { m_RightValue = v; }
};
class Bottom: public Right, public Left {
int m_BottomValue;
public:
Bottom() : m_BottomValue(-3) {}
int getBottomValue() { return m_BottomValue; }
void setBottomValue(int v) { m_BottomValue = v; }
};
template <typename T> void TemplateFunc() {
T *b = new T;
b->setBottomValue(3);
b->setRightValue(2);
b->setLeftValue(1);
if (b->getBottomValue() != 3)
printf("fail: expected bottom value to be 3 but got %d\n",
b->getBottomValue());
if (b->getRightValue() != 2)
printf("fail: expected right value to be 3 but got %d\n",
b->getRightValue());
if (b->getLeftValue() != 1)
printf("fail: expected left value to be 3 but got %d\n",
b->getLeftValue());
}
template <typename Q> void TemplateFuncUnrelated() {
Bottom *b = new Bottom;
b->setBottomValue(3);
b->setRightValue(2);
b->setLeftValue(1);
if (b->getBottomValue() != 3)
printf("fail: expected bottom value to be 3 but got %d\n",
b->getBottomValue());
if (b->getRightValue() != 2)
printf("fail: expected right value to be 3 but got %d\n",
b->getRightValue());
if (b->getLeftValue() != 1)
printf("fail: expected left value to be 3 but got %d\n",
b->getLeftValue());
}
TemplateFunc<Bottom>();
TemplateFuncUnrelated<MyClass>();
.q