Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ed559e

Browse files
committed
CPP: Extend the unions test.
1 parent cf20647 commit 4ed559e

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
| unions.cpp:4:8:4:12 | Entry | struct | |
2-
| unions.cpp:13:7:13:11 | Value | struct | union |
3-
| unions.cpp:19:8:19:22 | EntryWithMethod | struct | |
1+
| unions.cpp:4:8:4:12 | Entry | Struct |
2+
| unions.cpp:13:7:13:11 | Value | Struct, Union |
3+
| unions.cpp:19:8:19:22 | EntryWithMethod | Struct |
4+
| unions.cpp:27:9:27:20 | MyLocalUnion | LocalUnion, Struct, Union |
5+
| unions.cpp:33:7:33:13 | MyClass | |
6+
| unions.cpp:36:9:36:21 | MyNestedUnion | NestedUnion, Struct, Union |
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
import cpp
22

3-
from Class t, string struct, string union
4-
where if t instanceof Struct then struct = "struct" else struct = ""
5-
and if t instanceof Union then union = "union" else union = ""
6-
select t, struct, union
3+
string describe(Class c)
4+
{
5+
(
6+
c instanceof Struct and
7+
result = "Struct"
8+
) or (
9+
c instanceof Union and
10+
result = "Union"
11+
) or (
12+
c instanceof LocalUnion and
13+
result = "LocalUnion"
14+
) or (
15+
c instanceof NestedUnion and
16+
result = "NestedUnion"
17+
)
18+
}
19+
20+
from Class c
21+
select
22+
c,
23+
concat(describe(c), ", ")

cpp/ql/test/library-tests/unions/unions.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ struct EntryWithMethod: Entry {
2121
return i;
2222
}
2323
};
24+
25+
void myFunction()
26+
{
27+
union MyLocalUnion {
28+
int i;
29+
float f;
30+
};
31+
}
32+
33+
class MyClass
34+
{
35+
public:
36+
union MyNestedUnion {
37+
int i;
38+
float f;
39+
};
40+
};

0 commit comments

Comments
 (0)