* Fix #11417 FP knownConditionTrueFalse with container and brace init * Format * Format * Move to getInitListSize()
This commit is contained in:
parent
e4ee7cd59c
commit
7d6683fb78
|
@ -8085,6 +8085,15 @@ static std::vector<ValueFlow::Value> getContainerSizeFromConstructorArgs(const s
|
|||
return {};
|
||||
}
|
||||
|
||||
static bool valueFlowIsSameContainerType(const ValueType& contType, const Token* tok, const Settings* settings)
|
||||
{
|
||||
if (!tok || !tok->valueType() || !tok->valueType()->containerTypeToken)
|
||||
return false;
|
||||
|
||||
const ValueType tokType = ValueType::parseDecl(tok->valueType()->containerTypeToken, settings, true);
|
||||
return contType.isTypeEqual(&tokType);
|
||||
}
|
||||
|
||||
static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
|
||||
const ValueType* valueType,
|
||||
const Settings* settings,
|
||||
|
@ -8108,6 +8117,8 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
|
|||
initList = true;
|
||||
else if (vt.isIntegral() && astIsIntegral(args[0], false))
|
||||
initList = true;
|
||||
else if (args.size() == 1 && valueFlowIsSameContainerType(vt, tok->astOperand2(), settings))
|
||||
initList = false; // copy ctor
|
||||
}
|
||||
}
|
||||
if (!initList)
|
||||
|
|
|
@ -6317,6 +6317,22 @@ private:
|
|||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
|
||||
|
||||
code = "std::vector<int> g();\n" // #11417
|
||||
"int f() {\n"
|
||||
" std::vector<int> v{ g() };\n"
|
||||
" auto x = v.size();\n"
|
||||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 1));
|
||||
|
||||
code = "std::vector<int> g();\n"
|
||||
"int f() {\n"
|
||||
" std::vector<std::vector<int>> v{ g() };\n"
|
||||
" auto x = v.size();\n"
|
||||
" return x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 1));
|
||||
}
|
||||
|
||||
void valueFlowContainerElement()
|
||||
|
|
Loading…
Reference in New Issue