-
Couldn't load subscription status.
- Fork 1.5k
Fix #13773 (False positive: should not warn when different ternary 2nd and 3rd expressions happens to have same value) #7922
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
Conversation
…d and 3rd expressions happens to have same value)
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.
Pull Request Overview
This PR fixes issue #13773 by addressing false positives in the duplicate ternary expression checker. The fix distinguishes between truly identical expressions and expressions that happen to have the same value on the current platform. The key insight is that sizeof expressions may evaluate to the same value on one platform (e.g., sizeof(uint32_t) and sizeof(unsigned int) both being 4) but differ on others, so they shouldn't trigger warnings about duplicate values.
Key changes:
- Added a
platformIndependentparameter toisConstStatement()to distinguish between expressions that are platform-dependent (likesizeof) and those that aren't - Reordered the duplicate expression checks to prioritize identical expressions over equal values
- Updated test expectations to use
duplicateExpressionTernaryfor truly identical expressions andduplicateValueTernaryfor platform-independent equal values
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/checkother.cpp | Modified isConstStatement() to accept platformIndependent parameter, treating sizeof as non-constant when platform independence is required; reordered ternary duplicate checks |
| test/testother.cpp | Added test case for sizeof in ternary operators and updated existing test expectations to reflect the distinction between identical expressions and equal values |
| man/checkers/duplicateValueTernary.md | Added documentation explaining the duplicateValueTernary checker and when it triggers |
| man/checkers/duplicateExpressionTernary.md | Added documentation explaining the duplicateExpressionTernary checker for syntactically identical expressions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|



No description provided.