Fix FP uninitMemberVarPrivate with anonymous union (#3927)
This commit is contained in:
parent
39567ea8c8
commit
e0830693c3
|
@ -170,7 +170,7 @@ void CheckClass::constructors()
|
|||
if (var.isPrivate() && !var.isStatic() &&
|
||||
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
|
||||
++needInit;
|
||||
if (!var.isInit() && !var.hasDefault())
|
||||
if (!var.isInit() && !var.hasDefault() && var.nameToken()->scope() == scope) // don't warn for anonymous union members
|
||||
uninitVars.emplace_back(&var);
|
||||
else
|
||||
++haveInit;
|
||||
|
|
|
@ -3187,8 +3187,8 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarUnion1() { // ticket #3196
|
||||
check("class Fred\n"
|
||||
void uninitVarUnion1() {
|
||||
check("class Fred\n" // ticket #3196
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" union { int a; int b; };\n"
|
||||
|
@ -3197,6 +3197,12 @@ private:
|
|||
" { a = 0; }\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class Fred {\n"
|
||||
"private:\n"
|
||||
" union { int a{}; int b; };\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitVarUnion2() {
|
||||
|
|
Loading…
Reference in New Issue