Skip to content

Commit 19e3e3d

Browse files
committed
Fix #13816 FN uninitMemberVar with union (regression)
1 parent 6a71e3b commit 19e3e3d

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

lib/checkclass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ void CheckClass::constructors()
174174

175175
// #3196 => bailout if there are nested unions
176176
// TODO: handle union variables better
177-
{
178-
const bool bailout = std::any_of(scope->nestedList.cbegin(), scope->nestedList.cend(), [](const Scope* nestedScope) {
179-
return nestedScope->type == ScopeType::eUnion;
180-
});
181-
if (bailout)
182-
continue;
183-
}
177+
// {
178+
// const bool bailout = std::any_of(scope->nestedList.cbegin(), scope->nestedList.cend(), [](const Scope* nestedScope) {
179+
// return nestedScope->type == ScopeType::eUnion;
180+
// });
181+
// if (bailout)
182+
// continue;
183+
// }
184184

185185

186186
std::vector<Usage> usageList = createUsageList(scope);
@@ -311,7 +311,7 @@ void CheckClass::constructors()
311311
if (!precedes(scope->bodyStart, func.tokenDef))
312312
continue;
313313
const Scope *varType = var.typeScope();
314-
if (!varType || varType->type != ScopeType::eUnion) {
314+
{
315315
const bool derived = scope != var.scope();
316316
if (func.type == FunctionType::eConstructor &&
317317
func.nestedIn && (func.nestedIn->numConstructors - func.nestedIn->numCopyOrMoveConstructors) > 1 &&

test/testconstructors.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ class TestConstructors : public TestFixture {
13021302
" {\n"
13031303
" }\n"
13041304
"};");
1305-
TODO_ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::U' is not initialized in the constructor.\n", "", errout_str());
1305+
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::U' is not initialized in the constructor.\n", errout_str());
13061306
}
13071307

13081308

@@ -3428,9 +3428,6 @@ class TestConstructors : public TestFixture {
34283428
}
34293429

34303430
void uninitVarUnion2() {
3431-
// If the "data_type" is 0 it means union member "data" is invalid.
3432-
// So it's ok to not initialize "data".
3433-
// related forum: http://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&p=1806
34343431
check("union Data { int id; int *ptr; };\n"
34353432
"\n"
34363433
"class Fred {\n"
@@ -3441,7 +3438,7 @@ class TestConstructors : public TestFixture {
34413438
" Fred() : data_type(0)\n"
34423439
" { }\n"
34433440
"};");
3444-
ASSERT_EQUALS("", errout_str());
3441+
ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Fred::data' is not initialized in the constructor.\n", errout_str());
34453442
}
34463443

34473444
void uninitMissingFuncDef() {

0 commit comments

Comments
 (0)