Skip to content

Conversation

@danmar
Copy link
Owner

@danmar danmar commented Oct 28, 2025

No description provided.

@danmar danmar requested a review from Copilot October 28, 2025 16:29
Copy link

Copilot AI left a 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 platformIndependent parameter to isConstStatement() to distinguish between expressions that are platform-dependent (like sizeof) and those that aren't
  • Reordered the duplicate expression checks to prioritize identical expressions over equal values
  • Updated test expectations to use duplicateExpressionTernary for truly identical expressions and duplicateValueTernary for 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.

@sonarqubecloud
Copy link

@danmar danmar merged commit a8b7e2b into danmar:main Oct 29, 2025
2 checks passed
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.

1 participant