Skip to content

Commit c04e25e

Browse files
committed
Revert "#9391 Detecting uninited member variables with default ctor (cppcheck-opensource#2249)"
This reverts commit 08bc369.
1 parent b27fe83 commit c04e25e

2 files changed

Lines changed: 3 additions & 27 deletions

File tree

lib/checkclass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void CheckClass::constructors()
145145
std::vector<Usage> usage(scope->varlist.size());
146146

147147
for (const Function &func : scope->functionList) {
148-
if (!(func.hasBody() || func.isDefault()) || !(func.isConstructor() || func.type == Function::eOperatorEqual))
148+
if (!func.hasBody() || !(func.isConstructor() || func.type == Function::eOperatorEqual))
149149
continue;
150150

151151
// Bail: If initializer list is not recognized as a variable or type then skip since parsing is incomplete
@@ -159,8 +159,7 @@ void CheckClass::constructors()
159159
clearAllVar(usage);
160160

161161
std::list<const Function *> callstack;
162-
if (func.hasBody())
163-
initializeVarList(func, callstack, scope, usage);
162+
initializeVarList(func, callstack, scope, usage);
164163

165164
// Check if any variables are uninitialized
166165
int count = -1;

test/testconstructors.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,36 +385,13 @@ class TestConstructors : public TestFixture {
385385
ASSERT_EQUALS("", errout.str());
386386
}
387387

388-
void simple10() { // tickets #4388, #9391
388+
void simple10() { // ticket #4388
389389
check("class Fred {\n"
390390
"public:\n"
391391
" Fred() = default;\n"
392392
"private:\n"
393393
" int x;\n"
394394
"};");
395-
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout.str());
396-
397-
check("class Fred {\n"
398-
"public:\n"
399-
" Fred() = default;\n"
400-
" int x;\n"
401-
"};");
402-
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout.str());
403-
404-
check("class Fred {\n"
405-
"public:\n"
406-
" Fred();\n"
407-
" int x;\n"
408-
"};\n"
409-
"Fred::Fred()=default;");
410-
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout.str());
411-
412-
check("class Fred {\n"
413-
"public:\n"
414-
" Fred() = default;\n"
415-
"private:\n"
416-
" int x = 0;\n"
417-
"};");
418395
ASSERT_EQUALS("", errout.str());
419396
}
420397

0 commit comments

Comments
 (0)