useInitializationList: Skip warning when rhs is a multi line lambda. For readability it might be better to have assignments in constructor in this case.

This commit is contained in:
Daniel Marjamäki 2019-02-05 19:53:10 +01:00
parent 1ef13f8b06
commit 14a312e310
2 changed files with 15 additions and 0 deletions

View File

@ -946,6 +946,10 @@ void CheckClass::initializationListUsage()
if (var->isPointer() || var->isReference() || var->isEnumType() || var->valueType()->type > ValueType::Type::ITERATOR)
continue;
// bailout: multi line lambda in rhs => do not warn
if (findLambdaEndToken(tok->tokAt(2)) && tok->tokAt(2)->findExpressionStartEndTokens().second->linenr() > tok->tokAt(2)->linenr())
continue;
// Access local var member in rhs => do not warn
bool localmember = false;
visitAstNodes(tok->next()->astOperand2(),

View File

@ -6635,6 +6635,17 @@ private:
" }\n"
"};");
ASSERT_EQUALS("", errout.str());
// bailout: multi line lambda in rhs => do not warn
checkInitializationListUsage("class Fred {\n"
" std::function f;\n"
" Fred() {\n"
" f = [](){\n"
" return 1;\n"
" };\n"
" }\n"
"};");
ASSERT_EQUALS("", errout.str());
}