diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 017ff134f78..13996d0b965 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3293,7 +3293,7 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings } else if (ftok->str() == "{") { return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive; } else if (ftok->variable() && ftok == ftok->variable()->nameToken()) { // variable init/constructor call - if (ftok->variable()->type() && ftok->variable()->type()->needInitialization == Type::NeedInitialization::True) + if (ftok->variable()->type() && ftok->variable()->type()->classScope && ftok->variable()->type()->classScope->numConstructors == 0) return ExprUsage::Used; if (ftok->variable()->isStlType() || (ftok->variable()->valueType() && ftok->variable()->valueType()->container)) // STL types or containers don't initialize external variables return ExprUsage::Used; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 4da0ec4f086..845810084c7 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -7384,6 +7384,16 @@ class TestUninitVar : public TestFixture { "[test.cpp:8]: (error) Uninitialized variable: i\n" "[test.cpp:12]: (error) Uninitialized variable: i\n", errout.str()); + + valueFlowUninit("struct S {\n" + " S(char**);\n" + " int i;\n" + "};\n" + "void f() {\n" + " char* p;\n" + " S s(&p);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void uninitvar_memberfunction() {