Fixed #9821 (False positive: Delegating constructor and initialization list)
This commit is contained in:
parent
687b44dbb7
commit
f95a53b0ca
|
@ -943,9 +943,15 @@ void CheckClass::initializationListUsage()
|
|||
|
||||
for (const Scope *scope : mSymbolDatabase->functionScopes) {
|
||||
// Check every constructor
|
||||
if (!scope->function || (!scope->function->isConstructor()))
|
||||
if (!scope->function || !scope->function->isConstructor())
|
||||
continue;
|
||||
|
||||
// Do not warn when a delegate constructor is called
|
||||
if (const Token *initList = scope->function->constructorMemberInitialization()) {
|
||||
if (Token::Match(initList, ": %name% {|(") && initList->strAt(1) == scope->className)
|
||||
continue;
|
||||
}
|
||||
|
||||
const Scope* owner = scope->functionOf;
|
||||
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
|
||||
if (Token::Match(tok, "%name% (")) // Assignments might depend on this function call or if/for/while/switch statement from now on.
|
||||
|
|
|
@ -6567,6 +6567,19 @@ private:
|
|||
" Foo m_i;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkInitializationListUsage("class A {\n" // #9821 - delegate constructor
|
||||
"public:\n"
|
||||
" A() : st{} {}\n"
|
||||
"\n"
|
||||
" explicit A(const std::string &input): A() {\n"
|
||||
" st = input;\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"private:\n"
|
||||
" std::string st;\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue