CheckInternal: Complain about Token::Match pattern if %or% or %oror% is the only "complex" pattern

This commit is contained in:
PKEuS 2015-01-28 19:48:36 +01:00
parent 21bd1d080e
commit 3342ea4c54
2 changed files with 24 additions and 2 deletions

View File

@ -81,12 +81,28 @@ void CheckInternal::checkTokenMatchPatterns()
orInComplexPattern(tok, pattern, funcname);
// Check for signs of complex patterns
if (pattern.find_first_of("[|%") != std::string::npos)
if (pattern.find_first_of("[|") != std::string::npos)
continue;
else if (pattern.find("!!") != std::string::npos)
continue;
simplePatternError(tok, pattern, funcname);
bool complex = false;
size_t index = pattern.find('%');
while (index != std::string::npos) {
if (pattern.length() <= index + 2) {
complex = true;
break;
}
if (pattern[index + 1] == 'o' && pattern[index + 2] == 'r') // %or% or %oror%
index = pattern.find('%', index + 1);
else {
complex = true;
break;
}
index = pattern.find('%', index+1);
}
if (!complex)
simplePatternError(tok, pattern, funcname);
}
}

View File

@ -76,6 +76,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" const Token *tok;\n"
" Token::Match(tok, \"%or%\");\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Found simple pattern inside Token::Match() call: \"%or%\"\n", errout.str());
check("void f() {\n"
" const Token *tok;\n"
" Token::findmatch(tok, \";\");\n"