Skip to content

Commit c97a5ed

Browse files
committed
CPP: Add tests of AV Rule 114.ql with non-trivial return types.
1 parent 6811d52 commit c97a5ed

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/AV Rule 114.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
| test.c:39:9:39:14 | ExprStmt | Function f6 should return a value of type int but does not return a value here |
44
| test.cpp:16:1:18:1 | { ... } | Function g2 should return a value of type MyValue but does not return a value here |
55
| test.cpp:48:2:48:26 | if (...) ... | Function g7 should return a value of type MyValue but does not return a value here |
6+
| test.cpp:74:1:76:1 | { ... } | Function g10 should return a value of type second but does not return a value here |
7+
| test.cpp:80:1:82:1 | { ... } | Function g11 should return a value of type first but does not return a value here |
8+
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |
9+
| test.cpp:86:1:88:1 | { ... } | Function g12 should return a value of type second but does not return a value here |

cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/test.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,45 @@ MyValue g7(bool c)
5050
DONOTHING
5151
// BAD [the alert here is unfortunately placed]
5252
}
53+
54+
typedef void MYVOID;
55+
MYVOID g8()
56+
{
57+
// GOOD
58+
}
59+
60+
template<class T, class U>
61+
class TypePair
62+
{
63+
public:
64+
typedef T first;
65+
typedef U second;
66+
};
67+
68+
TypePair<void, int>::first g9()
69+
{
70+
// GOOD (the return type amounts to void)
71+
}
72+
73+
TypePair<void, int>::second g10()
74+
{
75+
// BAD (the return type amounts to int)
76+
}
77+
78+
template<class T>
79+
typename TypePair<void, T>::first g11()
80+
{
81+
// GOOD (the return type amounts to void) [FALSE POSITIVE]
82+
}
83+
84+
template<class T>
85+
typename TypePair<void, T>::second g12()
86+
{
87+
// BAD (the return type amounts to T / int)
88+
}
89+
90+
void instantiate()
91+
{
92+
g11<int>();
93+
g12<int>();
94+
}

0 commit comments

Comments
 (0)