I found an unitialized member in my code, that was not detected by cppcheck. See reproduction code below. Theoretically cppcheck is correct, the member is always true at the end of the constructor, but I was expecting some sort of message. Is there a way to convince cppcheck to give me a warning for this, or is this a bug?
Is there a way to convince cppcheck to give me a warning for this, or is this a bug?
It's a bug. I think that it might be relatively easy to fix.
For constructors, CheckUninitVar::checkScope could first determine members that are not initialized in the initialization list. Then for each such variable, execute CheckUninitVar::checkScopeForVariable.
Would you be interested to investigate this fix in Cppcheck?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the quick response ! I would be interested in fixing this issue, but truth be told, I don't think I will have time in the next couple of weeks. If that is not an issue, I'll have a look at it when I have time.
Best regards,
Ronnie
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I found an unitialized member in my code, that was not detected by cppcheck. See reproduction code below. Theoretically cppcheck is correct, the member is always true at the end of the constructor, but I was expecting some sort of message. Is there a way to convince cppcheck to give me a warning for this, or is this a bug?
Code:
`
struct A
{
A();
bool m_a;
};
void doSomething()
{
}
A::A()
{
if (m_a) {
doSomething();
}
else {
m_a = true;
}
}
`
Last edit: Ronnie Smets 2020-10-27
It's a bug. I think that it might be relatively easy to fix.
For constructors,
CheckUninitVar::checkScope
could first determine members that are not initialized in the initialization list. Then for each such variable, executeCheckUninitVar::checkScopeForVariable
.Would you be interested to investigate this fix in Cppcheck?
Hi Daniel,
Thanks for the quick response ! I would be interested in fixing this issue, but truth be told, I don't think I will have time in the next couple of weeks. If that is not an issue, I'll have a look at it when I have time.
Best regards,
Ronnie