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() &&
|
if (var.isPrivate() && !var.isStatic() &&
|
||||||
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
|
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
|
||||||
++needInit;
|
++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);
|
uninitVars.emplace_back(&var);
|
||||||
else
|
else
|
||||||
++haveInit;
|
++haveInit;
|
||||||
|
|
|
@ -3187,8 +3187,8 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarUnion1() { // ticket #3196
|
void uninitVarUnion1() {
|
||||||
check("class Fred\n"
|
check("class Fred\n" // ticket #3196
|
||||||
"{\n"
|
"{\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" union { int a; int b; };\n"
|
" union { int a; int b; };\n"
|
||||||
|
@ -3197,6 +3197,12 @@ private:
|
||||||
" { a = 0; }\n"
|
" { a = 0; }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("class Fred {\n"
|
||||||
|
"private:\n"
|
||||||
|
" union { int a{}; int b; };\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitVarUnion2() {
|
void uninitVarUnion2() {
|
||||||
|
|
Loading…
Reference in New Issue