mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
C++: add test for MemberFunction::getTypeOfThis()
This commit is contained in:
46
cpp/ql/test/library-tests/members/this/test.cpp
Normal file
46
cpp/ql/test/library-tests/members/this/test.cpp
Normal 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++;
|
||||
}
|
||||
};
|
||||
14
cpp/ql/test/library-tests/members/this/this.expected
Normal file
14
cpp/ql/test/library-tests/members/this/this.expected
Normal 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 * |
|
||||
8
cpp/ql/test/library-tests/members/this/this.ql
Normal file
8
cpp/ql/test/library-tests/members/this/this.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
import cpp
|
||||
|
||||
query predicate thisExprType(ThisExpr e, Type t) {
|
||||
t = e.getType()
|
||||
}
|
||||
|
||||
from MemberFunction f
|
||||
select f, f.getTypeOfThis()
|
||||
Reference in New Issue
Block a user