Multicondition: Fixed FP when using dynamic_cast

This commit is contained in:
Daniel Marjamäki 2014-07-30 11:23:09 +02:00
parent f5c872ed52
commit 473b1bdb2b
2 changed files with 17 additions and 10 deletions

View File

@ -44,12 +44,16 @@ public:
: Check(myName(), tokenizer, settings, errorLogger) {
}
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
CheckAssignIf checkAssignIf(tokenizer, settings, errorLogger);
checkAssignIf.multiCondition();
}
/** @brief Run checks against the simplified token list */
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
CheckAssignIf checkAssignIf(tokenizer, settings, errorLogger);
checkAssignIf.assignIf();
checkAssignIf.comparison();
checkAssignIf.multiCondition();
}
/** mismatching assignment / comparison */

View File

@ -41,34 +41,31 @@ private:
TEST_CASE(invalidMissingSemicolon); // crash as of #5867
}
void check(const char code[]) {
void check(const char code[], bool validate=true) {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.addEnabled("style");
CheckAssignIf checkAssignIf;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
checkAssignIf.runChecks(&tokenizer, &settings, this);
const std::string str1(tokenizer.tokens()->stringifyList(0,true));
tokenizer.simplifyTokenList2();
const std::string str2(tokenizer.tokens()->stringifyList(0,true));
checkAssignIf.runSimplifiedChecks(&tokenizer, &settings, this);
// Ensure that the test case is not bad.
if (str1 != str2) {
if (validate && str1 != str2) {
warn(("Unsimplified code in test case. It looks like this test "
"should either be cleaned up or moved to TestTokenizer or "
"TestSimplifyTokens instead.\nstr1="+str1+"\nstr2="+str2).c_str());
}
// Check char variable usage..
CheckAssignIf checkAssignIf(&tokenizer, &settings, this);
checkAssignIf.assignIf();
checkAssignIf.comparison();
checkAssignIf.multiCondition();
}
void assignAndCompare() {
@ -378,6 +375,12 @@ private:
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(WIDGET *widget) {\n"
" if (dynamic_cast<BUTTON*>(widget)){}\n"
" else if (dynamic_cast<LABEL*>(widget)){}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void invalidMissingSemicolon() {