C++: add test for MemberFunction::getTypeOfThis()

This commit is contained in:
Nick Rolfe
2020-06-25 16:55:13 +01:00
parent 8bd3be6e7b
commit 9e9d69238a
3 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
int global;
class C {
int x;
public:
void f1() {
// Implicit dereference of `this.`
x++;
}
void f2() {
// Explicit dereference of `this.`
this->x++;
}
int f3() const {
// We expect the type of `this` to be const-qualified.
return x;
}
int f4() volatile {
// We expect the type of `this` to be volatile-qualified.
return x;
}
int f5() const volatile {
// We expect the type of `this` to be qualified as both const and volatile.
return x;
}
void f6() {
// No use of `this`, but we still expect to be able to get its type.
global++;
}
};
// We want to test that D* is in the database even when there's no use of it,
// not even through an implicit dereference of `this`.
class D {
void f() {
global++;
}
};

View File

@@ -0,0 +1,14 @@
thisExprType
| test.cpp:11:5:11:5 | this | file://:0:0:0:0 | C * |
| test.cpp:16:5:16:8 | this | file://:0:0:0:0 | C * |
| test.cpp:21:12:21:12 | this | file://:0:0:0:0 | const C * |
| test.cpp:26:12:26:12 | this | file://:0:0:0:0 | volatile C * |
| test.cpp:31:12:31:12 | this | file://:0:0:0:0 | const volatile C * |
#select
| test.cpp:9:8:9:9 | f1 | file://:0:0:0:0 | C * |
| test.cpp:14:8:14:9 | f2 | file://:0:0:0:0 | C * |
| test.cpp:19:7:19:8 | f3 | file://:0:0:0:0 | const C * |
| test.cpp:24:7:24:8 | f4 | file://:0:0:0:0 | volatile C * |
| test.cpp:29:7:29:8 | f5 | file://:0:0:0:0 | const volatile C * |
| test.cpp:34:8:34:9 | f6 | file://:0:0:0:0 | C * |
| test.cpp:43:8:43:8 | f | file://:0:0:0:0 | D * |

View File

@@ -0,0 +1,8 @@
import cpp
query predicate thisExprType(ThisExpr e, Type t) {
t = e.getType()
}
from MemberFunction f
select f, f.getTypeOfThis()