CPP: Add a test of IncorrectConstructorDelegation.ql.

This commit is contained in:
Geoffrey White
2019-03-29 17:52:01 +00:00
parent 7dd7bf346d
commit 3ceacff0d4
3 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
| 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. |
| 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. |

View File

@@ -0,0 +1 @@
Likely Bugs/OO/IncorrectConstructorDelegation.ql

View File

@@ -0,0 +1,32 @@
class MyRect
{
public:
MyRect()
{
MyRect(100.0f, 100.0f); // BAD
}
MyRect(float _width, float _height) : width(_width), height(_height)
{
}
MyRect(float _width)
{
MyRect(_width, _width); // BAD
}
MyRect(int a) : MyRect(10.0f, 10.0f) // GOOD
{
MyRect other1(20.0f, 20.0f); // GOOD
MyRect other2 = MyRect(30.0f, 30.0f); // GOOD
}
MyRect(int a, int b)
{
*this = MyRect(40.0f, 40.0f); // GOOD
}
private:
float width, height;
};