C++: Add more tests of resolveClass

These tests exercise the problematic cases where a variable can appear
to have multiple types because of how we fail to account for qualified
names when comparing type names.
This commit is contained in:
Jonas Jensen
2018-09-14 14:23:31 +02:00
parent c9cb2a0d14
commit b633ee1bc4
12 changed files with 110 additions and 0 deletions

View File

@@ -24,3 +24,9 @@ class Damson {
int damson_x;
void foo();
};
namespace unrelated {
class AppleCompatible {
long apple_x;
};
}

View File

@@ -32,6 +32,9 @@
| b1.cpp:23:7:23:12 | Damson | 5 members | 2 locations | 1 | foo |
| b1.cpp:23:7:23:12 | Damson | 5 members | 2 locations | 2 | operator= |
| b1.cpp:23:7:23:12 | Damson | 5 members | 2 locations | 3 | operator= |
| b1.cpp:29:9:29:23 | AppleCompatible | 3 members | 1 locations | 0 | apple_x |
| b1.cpp:29:9:29:23 | AppleCompatible | 3 members | 1 locations | 1 | operator= |
| b1.cpp:29:9:29:23 | AppleCompatible | 3 members | 1 locations | 2 | operator= |
| b2.cpp:2:7:2:21 | AppleCompatible | 3 members | 2 locations | 0 | apple_x |
| b2.cpp:2:7:2:21 | AppleCompatible | 3 members | 2 locations | 1 | operator= |
| b2.cpp:2:7:2:21 | AppleCompatible | 3 members | 2 locations | 2 | operator= |

View File

@@ -10,6 +10,7 @@
| b1.cpp:11:7:11:22 | BananaCompatible | 0 | file://:0:0:0:0 | int | 1 types |
| b1.cpp:16:7:16:12 | Cherry | 0 | file://:0:0:0:0 | int | 1 types |
| b1.cpp:23:7:23:12 | Damson | 0 | file://:0:0:0:0 | int | 1 types |
| b1.cpp:29:9:29:23 | AppleCompatible | 0 | file://:0:0:0:0 | long | 1 types |
| b2.cpp:2:7:2:21 | AppleCompatible | 0 | file://:0:0:0:0 | int | 1 types |
| b2.cpp:9:7:9:22 | BananaCompatible | 0 | file://:0:0:0:0 | int | 1 types |
| b2.cpp:14:7:14:12 | Cherry | 0 | file://:0:0:0:0 | short | 1 types |

View File

@@ -1,2 +1,11 @@
| a.h:5:8:5:13 | cheese | x.cpp:6:10:6:12 | Foo | 3 |
| a.h:5:8:5:13 | cheese | x.cpp:12:9:12:11 | Foo | 3 |
| a.h:5:8:5:13 | cheese | y.cpp:4:8:4:10 | Foo | 3 |
| x.cpp:3:6:3:10 | bar_x | a.h:4:8:4:10 | Bar | 3 |
| x.cpp:19:6:19:10 | foo_x | x.cpp:6:10:6:12 | Foo | 3 |
| x.cpp:19:6:19:10 | foo_x | x.cpp:12:9:12:11 | Foo | 3 |
| x.cpp:19:6:19:10 | foo_x | y.cpp:4:8:4:10 | Foo | 3 |
| x.cpp:23:5:23:17 | templateField | x.cpp:6:10:6:12 | Foo | 3 |
| x.cpp:23:5:23:17 | templateField | x.cpp:12:9:12:11 | Foo | 3 |
| x.cpp:26:18:26:29 | template_foo | x.cpp:22:7:22:14 | Template<Foo *> | 3 |
| x.cpp:26:18:26:29 | template_foo | x.cpp:22:7:22:14 | Template<Foo *> | 3 |

View File

@@ -1,3 +1,31 @@
#include "a.h"
Bar *bar_x;
namespace unrelated {
struct Foo {
short val;
};
}
struct ContainsAnotherFoo {
class Foo {
long val;
};
};
// The type of `foo_x` should not refer to any of the above classes, none of
// which are named `Foo` in the global scope.
Foo *foo_x;
template<typename T>
class Template {
T templateField;
};
Template<Foo *> *template_foo;
// Instantiation of the template with unrelated classes named `Foo` should not
// get mixed up with the instantiation above.
template class Template<unrelated::Foo *>;
template class Template<ContainsAnotherFoo::Foo *>;

View File

@@ -0,0 +1,9 @@
#include "header.h"
struct MultipleDefsButSameHeader {
int i;
};
struct OneDefInDifferentFile {
int i;
};

View File

@@ -0,0 +1,6 @@
#include "header.h"
struct MultipleDefsButSameHeader {
char char1;
char char2;
};

View File

@@ -0,0 +1,5 @@
namespace foo {
class C;
C *x;
}

View File

@@ -0,0 +1,29 @@
namespace foo {
class C {
};
}
namespace bar {
class C {
};
}
class DefinedAndDeclared {
};
// Despite this declaration being present, the variable below is associated
// with the definition above rather than this declaration.
class DefinedAndDeclared;
DefinedAndDeclared *definedAndDeclared;
#include "header.h"
// Because there are multiple definitions of `MultipleDefsButSameHeader`, the
// type of this variable will refer to the declaration in `header.h` rather
// than any of the definitions.
MultipleDefsButSameHeader *mdbsh;
// Because there is only one definition of `OneDefInDifferentFile`, the type of
// this variable will refer to that definition.
OneDefInDifferentFile *odidf;

View File

@@ -0,0 +1,3 @@
struct MultipleDefsButSameHeader;
struct OneDefInDifferentFile;

View File

@@ -0,0 +1,6 @@
| decls.cpp:4:6:4:6 | x | defs.cpp:2:9:2:9 | C |
| decls.cpp:4:6:4:6 | x | defs.cpp:7:9:7:9 | C |
| defs.cpp:18:21:18:38 | definedAndDeclared | defs.cpp:11:7:11:24 | DefinedAndDeclared |
| defs.cpp:25:28:25:32 | mdbsh | c1.cpp:3:8:3:32 | MultipleDefsButSameHeader |
| defs.cpp:25:28:25:32 | mdbsh | c2.cpp:3:8:3:32 | MultipleDefsButSameHeader |
| defs.cpp:29:24:29:28 | odidf | c1.cpp:7:8:7:28 | OneDefInDifferentFile |

View File

@@ -0,0 +1,5 @@
import cpp
from Variable x
where exists(x.getFile().getRelativePath())
select x, x.getType().(PointerType).getBaseType()