Skip to content

Commit e073860

Browse files
Fix #10841 FN uninitMemberVar when member is being used in constructor (regression) (danmar#3909)
1 parent fb89a2c commit e073860

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
778778
}
779779

780780
// Calling member variable function?
781-
if (Token::Match(ftok->next(), "%var% . %name% (")) {
781+
if (Token::Match(ftok->next(), "%var% . %name% (") && !(ftok->next()->valueType() && ftok->next()->valueType()->pointer)) {
782782
for (const Variable &var : scope->varlist) {
783783
if (var.declarationId() == ftok->next()->varId()) {
784784
/** @todo false negative: we assume function changes variable state */

test/testconstructors.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class TestConstructors : public TestFixture {
179179
TEST_CASE(uninitVar31); // ticket #8271
180180
TEST_CASE(uninitVar32); // ticket #8835
181181
TEST_CASE(uninitVar33); // ticket #10295
182+
TEST_CASE(uninitVar34); // ticket #10841
182183
TEST_CASE(uninitVarEnum1);
183184
TEST_CASE(uninitVarEnum2); // ticket #8146
184185
TEST_CASE(uninitVarStream);
@@ -2822,6 +2823,15 @@ class TestConstructors : public TestFixture {
28222823
ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'B::x' is not initialized in the constructor.\n", errout.str());
28232824
}
28242825

2826+
void uninitVar34() { // ticket #10841
2827+
check("struct A { void f() {} };\n"
2828+
"struct B {\n"
2829+
" B() { a->f(); }\n"
2830+
" A* a;\n"
2831+
"};\n");
2832+
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout.str());
2833+
}
2834+
28252835
void uninitVarArray1() {
28262836
check("class John\n"
28272837
"{\n"

0 commit comments

Comments
 (0)