Skip to content

Fix ticket 8442: detect unselectable switch cases - #8815

Open
JeewoongKim wants to merge 3 commits into
cppcheck-opensource:mainfrom
JeewoongKim:fix-8442-unreachable-switch-case
Open

Fix ticket 8442: detect unselectable switch cases#8815
JeewoongKim wants to merge 3 commits into
cppcheck-opensource:mainfrom
JeewoongKim:fix-8442-unreachable-switch-case

Conversation

@JeewoongKim

Copy link
Copy Markdown

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
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
Author

Please add a short note in releasenotes.txt.

Added a short note. Thanks!

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