Skip to content

Commit 3ceacff

Browse files
committed
CPP: Add a test of IncorrectConstructorDelegation.ql.
1 parent 7dd7bf3 commit 3ceacff

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:7:3:7:24 | call to MyRect | The constructor MyRect may leave the instance uninitialized, as it tries to delegate to another constructor. |
2+
| test.cpp:16:3:16:24 | call to MyRect | The constructor MyRect may leave the instance uninitialized, as it tries to delegate to another constructor. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/OO/IncorrectConstructorDelegation.ql
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
class MyRect
3+
{
4+
public:
5+
MyRect()
6+
{
7+
MyRect(100.0f, 100.0f); // BAD
8+
}
9+
10+
MyRect(float _width, float _height) : width(_width), height(_height)
11+
{
12+
}
13+
14+
MyRect(float _width)
15+
{
16+
MyRect(_width, _width); // BAD
17+
}
18+
19+
MyRect(int a) : MyRect(10.0f, 10.0f) // GOOD
20+
{
21+
MyRect other1(20.0f, 20.0f); // GOOD
22+
MyRect other2 = MyRect(30.0f, 30.0f); // GOOD
23+
}
24+
25+
MyRect(int a, int b)
26+
{
27+
*this = MyRect(40.0f, 40.0f); // GOOD
28+
}
29+
30+
private:
31+
float width, height;
32+
};

0 commit comments

Comments
 (0)