Skip to content

Fix ticket 8442: detect unselectable switch cases - #8815

Merged
chrchr-github merged 4 commits into
cppcheck-opensource:mainfrom
JeewoongKim:fix-8442-unreachable-switch-case
Sep 6, 2026
Merged

Fix ticket 8442: detect unselectable switch cases#8815
chrchr-github merged 4 commits into
cppcheck-opensource:mainfrom
JeewoongKim:fix-8442-unreachable-switch-case

Conversation

@JeewoongKim

Copy link
Copy Markdown
Contributor

ValueFlow already knows the switch condition value in this case,
but the case labels were not checked against it.

This change uses that value to report case labels that cannot be
selected when the switch condition has a known integer value.

Added regression tests for enum and integer cases, unknown
switch values, and nested switches.

@JeewoongKim JeewoongKim changed the title Fix ticket #8442: detect unselectable switch cases Fix ticket 8442: detect unselectable switch cases Aug 29, 2026
@JeewoongKim
JeewoongKim force-pushed the fix-8442-unreachable-switch-case branch from 52f4e2e to f4ca315 Compare August 29, 2026 12:46
Comment thread lib/checkother.cpp Outdated
{
reportError(tok, Severity::style, "unreachableSwitchCase",
"Switch case '" + caseExpression +
"' can never be selected because the switch condition has a known value.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution. It might be helpful to mention the known value in the error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the message to include the known value. thanks.

@chrchr-github

Copy link
Copy Markdown
Collaborator

Please add a short note in releasenotes.txt.

@JeewoongKim

Copy link
Copy Markdown
Contributor Author

Please add a short note in releasenotes.txt.

Added a short note. Thanks!

@chrchr-github

Copy link
Copy Markdown
Collaborator

You may add yourself to the AUTHORS file if you'd like. Please add [skip ci] to the commit message.

@JeewoongKim

Copy link
Copy Markdown
Contributor Author

You may add yourself to the AUTHORS file if you'd like. Please add [skip ci] to the commit message.

Added myself to AUTHORS file with [skip ci]. Thanks!

@chrchr-github
chrchr-github merged commit f695ade into cppcheck-opensource:main Sep 6, 2026
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