Skip to content

Fix Trac 4651: avoid const-statement warnings for overloaded commas - #8893

Open
KiritoYG wants to merge 1 commit into
cppcheck-opensource:mainfrom
KiritoYG:codex/check-overloaded-comma
Open

KiritoYG wants to merge 1 commit into
cppcheck-opensource:mainfrom
KiritoYG:codex/check-overloaded-comma

Conversation

@KiritoYG

Copy link
Copy Markdown

Addresses Trac 4651. Boost.Assign expressions such as values += 2, 2 can perform useful work through an overloaded comma, but currently receive constStatement even in ordinary warning mode.

Require evidence of built-in operand types before treating a C++ comma expression as a constant statement. Account for assignment overloads separately: their inferred type is copied from the lhs, while the declared operator may return a different type. Conservatively inspect available return types without selecting an arbitrary overload; unknown, inherited, template and user-defined-conversion cases remain uncertain.

Keep warnings for ordinary scalar, pointer and C comma expressions, plus declared integer/pointer/void operator results. Add three test methods covering the original numeric/string-list use, member and free operators, chained commas, enums, anonymous namespaces, template ADL, mixed overloads and a ref-qualified/user-conversion regression. No Boost-name special case or library configuration change.

Validation:

  • Exact-original production with the new tests: 5,297 tests, 351 existing TODOs, the two expected regression failures.
  • Final Windows Clang/MinGW: 5,297 tests, 351 existing TODOs, zero failures. Twelve original/patched CLI comparisons pass; real-warning controls retain identical output and exit status.
  • Independent Linux GCC 11.4 verification of the exact source: warnings-as-errors build; 5,359 native tests, 360 existing TODOs, zero failures; all 33 focused incomplete-statement tests pass. The helper branch adds only its verification workflow.
  • Uncrustify 0.80.1 and git diff --check pass.

Two earlier Windows runs exited with 0xc0000005 while displaying TestIO::testPrintfArgumentVariables, whose checker does not invoke the new helper. The recorded offsets resolve to the unchanged Token::Match; neither a patch nor baseline cause is established. A bounded debugger run passed that location but was stopped after becoming slow in the existing TestValueFlow::valueFlowHang. The final complete native pass above includes the conversion regression.

This is conservative classification, not complete overload resolution: uncertain class expressions can suppress a genuine warning. The primitive/pointer/void controls limit that tradeoff and preserve the demonstrated existing diagnostics.

Please assign Trac 4651 to KiritoYG for this patch and confirm eligibility under the published USD 30 bounty bracket. After qualifying closure, I can use the documented bounty-request process; please also confirm the available settlement channel.

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