--------------------------------------------------------------------------- Check for statements like case A||B: in switch() ---------------------------------------------------------------------------
| 922 | // Check for statements like case A||B: in switch() |
| 923 | //--------------------------------------------------------------------------- |
| 924 | void CheckOtherImpl::checkSuspiciousCaseInSwitch() |
| 925 | { |
| 926 | if (!mSettings.certainty.isEnabled(Certainty::inconclusive) || !mSettings.severity.isEnabled(Severity::warning)) |
| 927 | return; |
| 928 | |
| 929 | logChecker("CheckOther::checkSuspiciousCaseInSwitch"); // warning,inconclusive |
| 930 | |
| 931 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 932 | |
| 933 | for (const Scope & scope : symbolDatabase->scopeList) { |
| 934 | if (scope.type != ScopeType::eSwitch) |
| 935 | continue; |
| 936 | |
| 937 | for (const Token* tok = scope.bodyStart->next(); tok != scope.bodyEnd; tok = tok->next()) { |
| 938 | if (tok->str() == "case") { |
| 939 | const Token* finding = nullptr; |
| 940 | for (const Token* tok2 = tok->next(); tok2; tok2 = tok2->next()) { |
| 941 | if (tok2->str() == ":") |
| 942 | break; |
| 943 | if (Token::Match(tok2, "[;}{]")) |
| 944 | break; |
| 945 | |
| 946 | if (tok2->str() == "?") |
| 947 | finding = nullptr; |
| 948 | else if (Token::Match(tok2, "&&|%oror%")) |
| 949 | finding = tok2; |
| 950 | } |
| 951 | if (finding) |
| 952 | suspiciousCaseInSwitchError(finding, finding->str()); |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | void CheckOtherImpl::suspiciousCaseInSwitchError(const Token* tok, const std::string& operatorString) |
| 959 | { |