parent
8a7992c6ac
commit
78dd29ada3
|
@ -164,7 +164,7 @@ void CheckClass::constructors()
|
||||||
if (scope->numConstructors == 0 && printStyle && !usedInUnion) {
|
if (scope->numConstructors == 0 && printStyle && !usedInUnion) {
|
||||||
// If there is a private variable, there should be a constructor..
|
// If there is a private variable, there should be a constructor..
|
||||||
for (const Variable &var : scope->varlist) {
|
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))) {
|
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
|
||||||
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
|
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -102,6 +102,7 @@ private:
|
||||||
TEST_CASE(noConstructor11); // ticket #3552
|
TEST_CASE(noConstructor11); // ticket #3552
|
||||||
TEST_CASE(noConstructor12); // #8951 - member initialization
|
TEST_CASE(noConstructor12); // #8951 - member initialization
|
||||||
TEST_CASE(noConstructor13); // #9998
|
TEST_CASE(noConstructor13); // #9998
|
||||||
|
TEST_CASE(noConstructor14); // #10770
|
||||||
|
|
||||||
TEST_CASE(forwardDeclaration); // ticket #4290/#3190
|
TEST_CASE(forwardDeclaration); // ticket #4290/#3190
|
||||||
|
|
||||||
|
@ -699,6 +700,17 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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 #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
|
||||||
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
|
// ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
|
||||||
void forwardDeclaration() {
|
void forwardDeclaration() {
|
||||||
|
|
Loading…
Reference in New Issue