Fix #10770 FP noConstructor with function pointer member (#3751)

This commit is contained in:
chrchr-github 2022-03-03 13:56:24 +01:00 committed by GitHub
parent 8a7992c6ac
commit 78dd29ada3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -164,7 +164,7 @@ void CheckClass::constructors()
if (scope->numConstructors == 0 && printStyle && !usedInUnion) {
// If there is a private variable, there should be a constructor..
for (const Variable &var : scope->varlist) {
if (var.isPrivate() && !var.isStatic() && !var.isInit() &&
if (var.isPrivate() && !var.isStatic() && !var.isInit() && !var.hasDefault() &&
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
break;

View File

@ -102,6 +102,7 @@ private:
TEST_CASE(noConstructor11); // ticket #3552
TEST_CASE(noConstructor12); // #8951 - member initialization
TEST_CASE(noConstructor13); // #9998
TEST_CASE(noConstructor14); // #10770
TEST_CASE(forwardDeclaration); // ticket #4290/#3190
@ -699,6 +700,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void noConstructor14() { // #10770
check("typedef void (*Func)();\n"
"class C {\n"
"public:\n"
" void f();\n"
"private:\n"
" Func fp = nullptr;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
void forwardDeclaration() {