diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 58a20689f13..72da844aa87 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -7157,7 +7157,10 @@ static void valueFlowContainerSize(const TokenList& tokenlist, for (const ValueFlow::Value& value : values) setTokenValue(tok, value, settings); } else if (Token::Match(tok, "%name%|;|{|}|> %var% =") && Token::Match(tok->tokAt(2)->astOperand2(), "[({]") && - (tok->tokAt(3) == tok->tokAt(2)->astOperand2() || settings.library.detectContainer(tok->tokAt(3)))) { + // init list + ((tok->tokAt(2) == tok->tokAt(2)->astOperand2()->astParent() && !tok->tokAt(2)->astOperand2()->astOperand2() && tok->tokAt(2)->astOperand2()->str() == "{") || + // constructor + (!Token::simpleMatch(tok->tokAt(2)->astOperand2()->astOperand1(), ".") && settings.library.detectContainer(tok->tokAt(3))))) { Token* containerTok = tok->next(); if (containerTok->exprId() == 0) continue; diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index b6d0ba760f9..2c0e836f7f3 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -211,6 +211,12 @@ bool QString7(QString s, const QString& l) { return l.startsWith(s); } +void QString_split(const char* name) { // #12998 + // cppcheck-suppress valueFlowBailoutIncompleteVar // FIXME + QStringList qsl = QString(name).split(';', Qt::SkipEmptyParts); + if (qsl.isEmpty()) {} +} + namespace NTestStd // #12355 { using namespace std;