Use parseDecl instead
This commit is contained in:
parent
423dcfd005
commit
831690f89b
|
@ -3625,8 +3625,9 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
|
|
||||||
bool isContainerOfPointers = true;
|
bool isContainerOfPointers = true;
|
||||||
const Token* containerTypeToken = tok->valueType()->containerTypeToken;
|
const Token* containerTypeToken = tok->valueType()->containerTypeToken;
|
||||||
if (containerTypeToken && Token::simpleMatch(containerTypeToken->previous(), "<") && containerTypeToken->previous()->link()) {
|
if (containerTypeToken) {
|
||||||
isContainerOfPointers = Token::simpleMatch(containerTypeToken->previous()->link()->previous(), "*");
|
ValueType vt = ValueType::parseDecl(containerTypeToken, settings);
|
||||||
|
isContainerOfPointers = vt.pointer > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LifetimeStore ls;
|
LifetimeStore ls;
|
||||||
|
|
|
@ -4176,6 +4176,28 @@ private:
|
||||||
" delete b;\n"
|
" delete b;\n"
|
||||||
"}\n" ,true);
|
"}\n" ,true);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct A {};\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" std::vector<A *, std::allocator<A*>> v;\n"
|
||||||
|
" A *a = new A();\n"
|
||||||
|
" v.push_back(a);\n"
|
||||||
|
" A *b = v.back();\n"
|
||||||
|
" v.pop_back();\n"
|
||||||
|
" delete b;\n"
|
||||||
|
"}\n" ,true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct A {};\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" std::vector<std::shared_ptr<A>> v;\n"
|
||||||
|
" std::shared_ptr<A> a = std::make_shared<A>();\n"
|
||||||
|
" v.push_back(a);\n"
|
||||||
|
" std::shared_ptr<A> b = v.back();\n"
|
||||||
|
" v.pop_back();\n"
|
||||||
|
" delete b;\n"
|
||||||
|
"}\n" ,true);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void invalidContainerLoop() {
|
void invalidContainerLoop() {
|
||||||
|
|
Loading…
Reference in New Issue