File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ void CheckClass::constructors()
164164 if (scope->numConstructors == 0 && printStyle && !usedInUnion) {
165165 // If there is a private variable, there should be a constructor..
166166 for (const Variable &var : scope->varlist ) {
167- if (var.isPrivate () && !var.isStatic () && !var.isInit () &&
167+ if (var.isPrivate () && !var.isStatic () && !var.isInit () && !var. hasDefault () &&
168168 (!var.isClass () || (var.type () && var.type ()->needInitialization == Type::NeedInitialization::True))) {
169169 noConstructorError (scope->classDef , scope->className , scope->classDef ->str () == " struct" );
170170 break ;
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ class TestConstructors : public TestFixture {
102102 TEST_CASE (noConstructor11); // ticket #3552
103103 TEST_CASE (noConstructor12); // #8951 - member initialization
104104 TEST_CASE (noConstructor13); // #9998
105+ TEST_CASE (noConstructor14); // #10770
105106
106107 TEST_CASE (forwardDeclaration); // ticket #4290/#3190
107108
@@ -699,6 +700,17 @@ class TestConstructors : public TestFixture {
699700 ASSERT_EQUALS (" " , errout.str ());
700701 }
701702
703+ void noConstructor14 () { // #10770
704+ check (" typedef void (*Func)();\n "
705+ " class C {\n "
706+ " public:\n "
707+ " void f();\n "
708+ " private:\n "
709+ " Func fp = nullptr;\n "
710+ " };\n " );
711+ ASSERT_EQUALS (" " , errout.str ());
712+ }
713+
702714 // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
703715 // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"
704716 void forwardDeclaration () {
You can’t perform that action at this time.
0 commit comments