Use parseDecl instead

This commit is contained in:
Paul 2020-07-16 14:33:39 -05:00
parent 423dcfd005
commit 831690f89b
2 changed files with 25 additions and 2 deletions

View File

@ -3625,8 +3625,9 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
bool isContainerOfPointers = true;
const Token* containerTypeToken = tok->valueType()->containerTypeToken;
if (containerTypeToken && Token::simpleMatch(containerTypeToken->previous(), "<") && containerTypeToken->previous()->link()) {
isContainerOfPointers = Token::simpleMatch(containerTypeToken->previous()->link()->previous(), "*");
if (containerTypeToken) {
ValueType vt = ValueType::parseDecl(containerTypeToken, settings);
isContainerOfPointers = vt.pointer > 0;
}
LifetimeStore ls;

View File

@ -4176,6 +4176,28 @@ private:
" delete b;\n"
"}\n" ,true);
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() {