Repository navigation
Partial fix for #15048 Inconsistent error severity for uninitvar #8966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review This expectation locks in a downgrade: |
||
| "[test.cpp:3:9]: note: Assuming condition is true\n" | ||
| "[test.cpp:4:16]: note: Uninitialized variable: i\n", | ||
| errout_str()); | ||
| } | ||
|
|
||
| void uninitvar_memberfunction() { | ||
| // # 8715 | ||
| valueFlowUninit("struct C {\n" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
conditionalis not a reliable sign that the read is only possibly uninitialized. Here it gets set depending on what follows theif.int i; if (b) return i; return 0;still gives error.int i; if (b) return i; i = 1; return i;now gives warning.if (b) g(i); i = 1; g(i);is also demoted to warning.In each case the read inside the branch is uninitialized every time it executes, so these are definite bugs that used to be errors. The patch makes the severity less consistent instead of more.