mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
CPP: Add a test of IncorrectConstructorDelegation.ql.
This commit is contained in:
@@ -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. |
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/OO/IncorrectConstructorDelegation.ql
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user