Skip to content
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

Fixed #12260 (false positive: unusedVariable with side effects in member initialization) #5762

Merged
merged 2 commits into from
Dec 14, 2023
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
3 changes: 0 additions & 3 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,9 +1630,6 @@ bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type)

bool CheckUnusedVar::isVariableWithoutSideEffects(const Variable& var)
{
if (var.isPointer())
return true;

const Type* variableType = var.type();
if (variableType) {
if (!isRecordTypeWithoutSideEffects(variableType))
Expand Down
14 changes: 14 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,20 @@ class TestUnusedVar : public TestFixture {
"}");
TODO_ASSERT_EQUALS("error", "", errout.str());

// constructor with hidden definition
functionVariableUsage(
"class B {\n"
"public:\n"
" B();\n"
"};\n"
"class A {\n"
" B* b = new B;\n"
"};\n"
"int main() {\n"
" A a;\n"
"}");
TODO_ASSERT_EQUALS("error", "", errout.str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert looks wrong. Looks like a copy and paste error from the one above - and that also looks fishy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check it. Thank you

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one above is actually ok as a TODO, since that constructor has no side effects (class F).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one above is actually ok as a TODO, since that constructor has no side effects (class F).

"fishy" in the sense that the expected message is just bogus. I did not look at the contents of it.


// side-effect variable
functionVariableUsage(
"class F {\n"
Expand Down
Loading