Skip to content

[MERGED] warning 24X: redundant code: switch control expression is constant #548

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

Closed
wants to merge 2 commits into from

Conversation

Daniel-Cortez
Copy link
Contributor

@Daniel-Cortez Daniel-Cortez commented Jun 30, 2020

What this PR does / why we need it:

This PR allows the compiler to warn the user about redundant code if a switch control expression has a constant result, as suggested in #528.

switch (1) // warning 24X: redundant code: switch control expression is constant
{
    // ...
}

There are already similar warnings for if, while, do-while and for statements ("205: redundant code: constant expression is zero" and "206: redundant test: constant expression is non-zero"), so I think it should make sense to adopt a similar warning for switch.

Which issue(s) this PR fixes:

Fixes #

What kind of pull this is:

  • A Bug Fix
  • A New Feature
  • Some repository meta (documentation, etc)
  • Other

Additional Documentation:

@Daniel-Cortez Daniel-Cortez requested a review from a team as a code owner June 30, 2020 13:24
@Y-Less Y-Less closed this Sep 19, 2020
@Y-Less Y-Less changed the title warning 24X: redundant code: switch control expression is constant [MERGED] warning 24X: redundant code: switch control expression is constant Sep 20, 2020
@Daniel-Cortez Daniel-Cortez deleted the wswitch-constexpr branch October 19, 2020 12:56
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