CheckInternal: Complain about Token::Match pattern if %or% or %oror% is the only "complex" pattern
This commit is contained in:
parent
21bd1d080e
commit
3342ea4c54
|
@ -81,11 +81,27 @@ void CheckInternal::checkTokenMatchPatterns()
|
||||||
orInComplexPattern(tok, pattern, funcname);
|
orInComplexPattern(tok, pattern, funcname);
|
||||||
|
|
||||||
// Check for signs of complex patterns
|
// Check for signs of complex patterns
|
||||||
if (pattern.find_first_of("[|%") != std::string::npos)
|
if (pattern.find_first_of("[|") != std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
else if (pattern.find("!!") != std::string::npos)
|
else if (pattern.find("!!") != std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
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);
|
simplePatternError(tok, pattern, funcname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,12 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
check("void f() {\n"
|
||||||
" const Token *tok;\n"
|
" const Token *tok;\n"
|
||||||
" Token::findmatch(tok, \";\");\n"
|
" Token::findmatch(tok, \";\");\n"
|
||||||
|
|
Loading…
Reference in New Issue