Get type from smartpointer (#4608)

* Fix #11223 checkLibraryFunction treats "auto" as type

* Use utility function

* Get type from 'auto p = new ...'

* Fix merge

* Add test for recent fix

* Format

* Get type from smartpointer
This commit is contained in:
chrchr-github 2022-12-03 07:50:21 +01:00 committed by GitHub
parent 7d6683fb78
commit 0854fda28a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -2278,6 +2278,11 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token * tok)
if (vt && vt->containerTypeToken)
return { vt->containerTypeToken, vt->containerTypeToken->linkAt(-1) };
}
if (astIsSmartPointer(var->nameToken())) {
const ValueType* vt = var->valueType();
if (vt && vt->smartPointerTypeToken)
return { vt->smartPointerTypeToken, vt->smartPointerTypeToken->linkAt(-1) };
}
}
return {var->typeStartToken(), var->typeEndToken()->next()};
} else if (Token::simpleMatch(tok, "return")) {

View File

@ -1916,6 +1916,12 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" auto p = std::make_shared<std::vector<int>>();\n"
" p->push_back(1);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
settings.severity = severity_old;
settings.checkLibrary = false;
}

View File

@ -6758,6 +6758,8 @@ private:
"void h() { "
" [func=foo<int>]{func();}(); "
"}"));
ASSERT_NO_THROW(tokenizeAndStringify("template <class T> constexpr int n = 1;\n"
"template <class T> T a[n<T>];\n"));
// op op