Skip to content

Commit 9e9d692

Browse files
committed
C++: add test for MemberFunction::getTypeOfThis()
1 parent 8bd3be6 commit 9e9d692

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
int global;
3+
4+
class C {
5+
int x;
6+
7+
public:
8+
9+
void f1() {
10+
// Implicit dereference of `this.`
11+
x++;
12+
}
13+
14+
void f2() {
15+
// Explicit dereference of `this.`
16+
this->x++;
17+
}
18+
19+
int f3() const {
20+
// We expect the type of `this` to be const-qualified.
21+
return x;
22+
}
23+
24+
int f4() volatile {
25+
// We expect the type of `this` to be volatile-qualified.
26+
return x;
27+
}
28+
29+
int f5() const volatile {
30+
// We expect the type of `this` to be qualified as both const and volatile.
31+
return x;
32+
}
33+
34+
void f6() {
35+
// No use of `this`, but we still expect to be able to get its type.
36+
global++;
37+
}
38+
};
39+
40+
// We want to test that D* is in the database even when there's no use of it,
41+
// not even through an implicit dereference of `this`.
42+
class D {
43+
void f() {
44+
global++;
45+
}
46+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
thisExprType
2+
| test.cpp:11:5:11:5 | this | file://:0:0:0:0 | C * |
3+
| test.cpp:16:5:16:8 | this | file://:0:0:0:0 | C * |
4+
| test.cpp:21:12:21:12 | this | file://:0:0:0:0 | const C * |
5+
| test.cpp:26:12:26:12 | this | file://:0:0:0:0 | volatile C * |
6+
| test.cpp:31:12:31:12 | this | file://:0:0:0:0 | const volatile C * |
7+
#select
8+
| test.cpp:9:8:9:9 | f1 | file://:0:0:0:0 | C * |
9+
| test.cpp:14:8:14:9 | f2 | file://:0:0:0:0 | C * |
10+
| test.cpp:19:7:19:8 | f3 | file://:0:0:0:0 | const C * |
11+
| test.cpp:24:7:24:8 | f4 | file://:0:0:0:0 | volatile C * |
12+
| test.cpp:29:7:29:8 | f5 | file://:0:0:0:0 | const volatile C * |
13+
| test.cpp:34:8:34:9 | f6 | file://:0:0:0:0 | C * |
14+
| test.cpp:43:8:43:8 | f | file://:0:0:0:0 | D * |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
3+
query predicate thisExprType(ThisExpr e, Type t) {
4+
t = e.getType()
5+
}
6+
7+
from MemberFunction f
8+
select f, f.getTypeOfThis()

0 commit comments

Comments
 (0)