Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,8 +3425,14 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
// TODO: resolve multiple constructors
if (ftok->variable()->type() && ftok->variable()->type()->classScope) {
const int nCtor = ftok->variable()->type()->classScope->numConstructors;
if (nCtor == 0)
if (nCtor == 0) {
if (indirect > 0) {
std::vector<const Variable*> argvar = getArgumentVars(ftok->astParent(), argnr);
Comment thread
chrchr-github marked this conversation as resolved.
Outdated
if (argvar.size() == 1 && argvar[0]->valueType() && argvar[0]->valueType()->pointer == indirect)
return ExprUsage::NotUsed;
}
return ExprUsage::Used;
}
if (nCtor == 1) {
const Scope* scope = ftok->variable()->type()->classScope;
auto it = std::find_if(scope->functionList.begin(), scope->functionList.end(), [](const Function& f) {
Expand Down
2 changes: 2 additions & 0 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,8 @@ const ::Type* Token::typeOf(const Token* tok, const Token** typeTok)
return tok->variable()->type();
if (tok->function())
return tok->function()->retType;
if (tok->valueType() && tok->valueType()->typeScope && tok->valueType()->typeScope->definedType)
return tok->valueType()->typeScope->definedType;
if (Token::simpleMatch(tok, "return")) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Scope *scope = tok->scope();
Expand Down
8 changes: 8 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7776,6 +7776,14 @@ class TestUninitVar : public TestFixture {
" return (&s)->y;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5:16]: (error) Uninitialized variable: s.y [uninitvar]\n", errout_str());

valueFlowUninit("struct S { int* p; };\n" // #14640
"void f() {\n"
" int x;\n"
" S s{ &x };\n"
" *s.p = 0;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void valueFlowUninitForLoop()
Expand Down
Loading