diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index e4b2f6207..933490df2 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -2631,13 +2631,15 @@ static ExprEngine::ValuePtr createVariableValue(const Variable &var, Data &data) return value; } if (valueType->type == ValueType::Type::RECORD) { - bool init = true; + bool uninitData = true; if (var.isLocal() && !var.isStatic()) { - init = valueType->typeScope && - valueType->typeScope->definedType && - valueType->typeScope->definedType->needInitialization != Type::NeedInitialization::False; + uninitData = !valueType->typeScope || + !valueType->typeScope->definedType || + valueType->typeScope->definedType->needInitialization != Type::NeedInitialization::False; } - return createStructVal(valueType->typeScope, init, data); + if (var.isArgument() && var.isConst()) + uninitData = false; + return createStructVal(valueType->typeScope, uninitData, data); } if (valueType->smartPointerType) { auto structValue = createStructVal(valueType->smartPointerType->classScope, var.isLocal() && !var.isStatic(), data); diff --git a/test/testbughuntingchecks.cpp b/test/testbughuntingchecks.cpp index c1f14b072..c5c4635c9 100644 --- a/test/testbughuntingchecks.cpp +++ b/test/testbughuntingchecks.cpp @@ -222,6 +222,15 @@ private: check("void foo(int *p) { if (p) *p=0; }"); ASSERT_EQUALS("", errout.str()); + + check("class C {\n" + "public:\n" + " C();\n" + " int x;\n" + "};\n" + "\n" + "void foo(const C &c) { int x = c.x; }"); + ASSERT_EQUALS("", errout.str()); } void uninit_malloc() {