CheckString: Fix FP when macros are used.
This commit is contained in:
parent
9c8ff5b89c
commit
8e2f7812fd
|
@ -85,6 +85,7 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
|
||||||
if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
|
if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
|
||||||
const std::string &str1 = tok->strAt(2);
|
const std::string &str1 = tok->strAt(2);
|
||||||
const std::string &str2 = tok->strAt(4);
|
const std::string &str2 = tok->strAt(4);
|
||||||
|
if (!tok->isExpandedMacro() && !tok->tokAt(2)->isExpandedMacro() && !tok->tokAt(4)->isExpandedMacro())
|
||||||
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
||||||
tok = tok->tokAt(5);
|
tok = tok->tokAt(5);
|
||||||
} else if (Token::Match(tok->tokAt(2), "%name% , %name% ,|)")) {
|
} else if (Token::Match(tok->tokAt(2), "%name% , %name% ,|)")) {
|
||||||
|
|
|
@ -155,6 +155,16 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Unnecessary comparison of static strings.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Unnecessary comparison of static strings.\n", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" if (strcmp($\"00FF00\", \"00FF00\") == 0) {}"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" if ($strcmp(\"00FF00\", \"00FF00\") == 0) {}"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("int main()\n"
|
check("int main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if (stricmp(\"hotdog\",\"HOTdog\") == 0)"
|
" if (stricmp(\"hotdog\",\"HOTdog\") == 0)"
|
||||||
|
|
Loading…
Reference in New Issue