File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -943,9 +943,15 @@ void CheckClass::initializationListUsage()
943943
944944 for (const Scope *scope : mSymbolDatabase ->functionScopes ) {
945945 // Check every constructor
946- if (!scope->function || ( !scope->function ->isConstructor () ))
946+ if (!scope->function || !scope->function ->isConstructor ())
947947 continue ;
948948
949+ // Do not warn when a delegate constructor is called
950+ if (const Token *initList = scope->function ->constructorMemberInitialization ()) {
951+ if (Token::Match (initList, " : %name% {|(" ) && initList->strAt (1 ) == scope->className )
952+ continue ;
953+ }
954+
949955 const Scope* owner = scope->functionOf ;
950956 for (const Token* tok = scope->bodyStart ; tok != scope->bodyEnd ; tok = tok->next ()) {
951957 if (Token::Match (tok, " %name% (" )) // Assignments might depend on this function call or if/for/while/switch statement from now on.
Original file line number Diff line number Diff line change @@ -6567,6 +6567,19 @@ class TestClass : public TestFixture {
65676567 " Foo m_i;\n "
65686568 " };" );
65696569 ASSERT_EQUALS (" " , errout.str ());
6570+
6571+ checkInitializationListUsage (" class A {\n " // #9821 - delegate constructor
6572+ " public:\n "
6573+ " A() : st{} {}\n "
6574+ " \n "
6575+ " explicit A(const std::string &input): A() {\n "
6576+ " st = input;\n "
6577+ " }\n "
6578+ " \n "
6579+ " private:\n "
6580+ " std::string st;\n "
6581+ " };" );
6582+ ASSERT_EQUALS (" " , errout.str ());
65706583 }
65716584
65726585
You can’t perform that action at this time.
0 commit comments