Skip to content

Fix #14371: FP redundantAssignment for nested union members#8748

Open
DanTheMan2000 wants to merge 2 commits into
cppcheck-opensource:mainfrom
DanTheMan2000:fix-14371-union-redundant-assignment
Open

Fix #14371: FP redundantAssignment for nested union members#8748
DanTheMan2000 wants to merge 2 commits into
cppcheck-opensource:mainfrom
DanTheMan2000:fix-14371-union-redundant-assignment

Conversation

@DanTheMan2000

Copy link
Copy Markdown

No description provided.

@DanTheMan2000
DanTheMan2000 force-pushed the fix-14371-union-redundant-assignment branch from c50ae02 to 4761bef Compare July 23, 2026 04:24
@DanTheMan2000

Copy link
Copy Markdown
Author

There were actually two variants of this false positive. The one from the ticket involved reading another union member inside a larger expression. The other case is where an assignment to a different union member sits between the two writes to the member being reassigned. Added tests covering both in testother.cpp.

@DanTheMan2000
DanTheMan2000 force-pushed the fix-14371-union-redundant-assignment branch from 4761bef to d5f2fb4 Compare July 23, 2026 04:52
@DanTheMan2000

Copy link
Copy Markdown
Author

Added a couple of control tests to go with the false-positive ones, wanted to make sure the fix is scoped to the actual variable being reassigned.

@chrchr-github

Copy link
Copy Markdown
Collaborator

Thanks for your contribution.
As far as I see, the added tests all use the same union definition. Can you consolidate them into one test case containing multiple functions?

The separate #14371 tests all used the same union definition, so combine them into one test case containing multiple functions as requested in review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants