Fixed false positive when ternary operator is used: case A&&B?B:A:
This commit is contained in:
parent
0ac4c3baf4
commit
068c695bd1
|
@ -1074,11 +1074,21 @@ void CheckOther::checkSuspiciousCaseInSwitch()
|
|||
|
||||
for (const Token* tok = i->classStart->next(); tok != i->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "case") {
|
||||
const Token* end = 0;
|
||||
for (const Token* tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||
if (Token::Match(tok2, "[:;}{]"))
|
||||
if (tok2->str() == ":") {
|
||||
end = tok2;
|
||||
break;
|
||||
if (Token::Match(tok2, "&&|%oror%"))
|
||||
suspiciousCaseInSwitchError(tok, tok2->str());
|
||||
}
|
||||
if (Token::Match(tok2, "[?;}{]")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (end) {
|
||||
const Token* finding = Token::findmatch(tok->next(), "&&|%oror%", end);
|
||||
if (finding)
|
||||
suspiciousCaseInSwitchError(tok, finding->str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2750,6 +2750,14 @@ private:
|
|||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" switch(a) {\n"
|
||||
" case A&&B?B:A:\n"
|
||||
" foo();\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue