Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/checkuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ void CheckUninitVarImpl::uninitvarError(const Token* tok, const ValueFlow::Value
const std::string& varname = ltok ? ltok->expressionString() : "x";
ErrorPath errorPath = v.errorPath;
errorPath.emplace_back(tok, "");
auto severity = v.isKnown() ? Severity::error : Severity::warning;
auto severity = v.isKnown() && !v.conditional ? Severity::error : Severity::warning;
Comment thread
danmar marked this conversation as resolved.
Resolved
auto certainty = v.isInconclusive() ? Certainty::inconclusive : Certainty::normal;
if (v.subexpressions.empty()) {
reportError(std::move(errorPath),
Expand Down
18 changes: 18 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class TestUninitVar : public TestFixture {
TEST_CASE(valueFlowUninitBreak);
TEST_CASE(valueFlowUninitStructMembers);
TEST_CASE(valueFlowUninitForLoop);
TEST_CASE(valueFlowUninitErrorPath);
TEST_CASE(uninitvar_ipa);
TEST_CASE(uninitvar_memberfunction);
TEST_CASE(uninitvar_nonmember); // crash in ycmd test
Expand Down Expand Up @@ -7945,6 +7946,23 @@ class TestUninitVar : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void valueFlowUninitErrorPath()
{
setMultiline();

valueFlowUninit("void f(bool b) {\n"
" int i;\n"
" if (b)\n"
" return i;\n"
" i = 1;\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4:16]: warning: Uninitialized variable: i [uninitvar]\n"
Comment thread
danmar marked this conversation as resolved.
Resolved
"[test.cpp:3:9]: note: Assuming condition is true\n"
Comment thread
chrchr-github marked this conversation as resolved.
Resolved
"[test.cpp:4:16]: note: Uninitialized variable: i\n",
errout_str());
}

void uninitvar_memberfunction() {
// # 8715
valueFlowUninit("struct C {\n"
Expand Down
Loading