I am evaluating cppcheck to see if will find uninitialized variables members/variables... of a templated class type. But it doesn't seem to.
Invoked like so:
/usr/local/bin/cppcheck --enable=all --xml-version=2
Here is my test code:
enumclassViewMode{One=1,Two=2,Three=3,Four=4};classTestClass{public:TestClass() {}};template<typenameT,boolC=std::is_copy_constructible<T>::value>classTemplateTest{public:TemplateTest() {}TemplateTest(constT&value):value_(value){}TemplateTest(constTemplateTest&)=delete;TemplateTest(TemplateTest<T,C>&&rhs):value_(std::move(rhs.value_)){}TemplateTest(T&&value):value_(std::move(value)){}private:Tvalue_;};classStaticAnalysisTest{public:StaticAnalysisTest() {}voidDoSomething() {}private:ViewModeviewMode_;//this uninitialized warning is foundTemplateTest<ViewMode>viewMode2_;//this one is not};
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for evaluating Cppcheck. A warning is given for the second example, in case you add the --inconclusive flag, for example:
$ cppcheck --enable=all --inconclusive uninitmembervar.cpp
[uninitmembervar.cpp:6]: (warning, inconclusive) Member variable 'Foo::m_nValue' is not initialized in the constructor.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This does not give a warning about tValue not being initialized. But if I remove the second parameter of the template (bool C), it does warn about tValue not being initialized.
Any idea why?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am evaluating cppcheck to see if will find uninitialized variables members/variables... of a templated class type. But it doesn't seem to.
Invoked like so:
/usr/local/bin/cppcheck --enable=all --xml-version=2
Here is my test code:
I distilled the problem further:
This does not generate an unitialized variable warning, but when I comment out:
//Foo(int value) : m_nValue(value) {}
it does
Thank you for evaluating Cppcheck. A warning is given for the second example, in case you add the --inconclusive flag, for example:
That works, thanks!!
That works, thanks!!
Ok a quick follow up, while that works, it still does not in the first example I gave. Here is distilled example of the template case:
This does not give a warning about tValue not being initialized. But if I remove the second parameter of the template (bool C), it does warn about tValue not being initialized.
Any idea why?
Hi,
it seems that you have found a case, where Cppcheck is currently blind. I have created a ticket about this test case on our bugtracker #8162.
Many thanks for evaluating Cppcheck!
Last edit: orbitcowboy 2017-08-13