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:
parent
7d6683fb78
commit
0854fda28a
|
@ -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")) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue