Fix 9836: False negative: No invalidContainer when using vector of vectors (#3580)
* Fix 9836: False negative: No invalidContainer when using vector of vectors * Format
This commit is contained in:
parent
143ddf2758
commit
1e327dfbd3
|
@ -5698,6 +5698,7 @@ void SymbolDatabase::setValueType(Token *tok, const Variable &var)
|
|||
valuetype.typeScope = var.typeScope();
|
||||
if (var.valueType()) {
|
||||
valuetype.container = var.valueType()->container;
|
||||
valuetype.containerTypeToken = var.valueType()->containerTypeToken;
|
||||
}
|
||||
valuetype.smartPointerType = var.smartPointerType();
|
||||
if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) {
|
||||
|
@ -6548,20 +6549,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
|
|||
const Token *typeStartToken = tok->astOperand1();
|
||||
while (typeStartToken && typeStartToken->str() == "::")
|
||||
typeStartToken = typeStartToken->astOperand1();
|
||||
if (const Library::Container *c = mSettings->library.detectContainer(typeStartToken)) {
|
||||
if (mSettings->library.detectContainer(typeStartToken) ||
|
||||
mSettings->library.detectSmartPointer(typeStartToken)) {
|
||||
ValueType vt;
|
||||
vt.pointer = 0;
|
||||
vt.container = c;
|
||||
vt.type = ValueType::Type::CONTAINER;
|
||||
setValueType(tok, vt);
|
||||
continue;
|
||||
}
|
||||
if (const Library::SmartPointer* sp = mSettings->library.detectSmartPointer(typeStartToken)) {
|
||||
ValueType vt;
|
||||
vt.type = ValueType::Type::SMART_POINTER;
|
||||
vt.smartPointer = sp;
|
||||
setValueType(tok, vt);
|
||||
continue;
|
||||
if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings)) {
|
||||
setValueType(tok, vt);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string e = tok->astOperand1()->expressionString();
|
||||
|
|
|
@ -4925,6 +4925,18 @@ private:
|
|||
" cb[i] = b[i];\n"
|
||||
"}\n",true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #9836
|
||||
check("void f() {\n"
|
||||
" auto v = std::vector<std::vector<std::string> >{ std::vector<std::string>{ \"hello\" } };\n"
|
||||
" auto p = &(v.at(0).at(0));\n"
|
||||
" v.clear();\n"
|
||||
" std::cout << *p << std::endl;\n"
|
||||
"}\n",
|
||||
true);
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Using pointer to local variable 'v' that may be invalid.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void invalidContainerLoop() {
|
||||
|
|
Loading…
Reference in New Issue