CheckString: Fix FP when macros are used.

This commit is contained in:
Daniel Marjamäki 2016-01-13 20:32:40 +01:00
parent 9c8ff5b89c
commit 8e2f7812fd
2 changed files with 12 additions and 1 deletions

View File

@ -85,7 +85,8 @@ void CheckString::checkAlwaysTrueOrFalseStringCompare()
if (Token::Match(tok->tokAt(2), "%str% , %str% ,|)")) {
const std::string &str1 = tok->strAt(2);
const std::string &str2 = tok->strAt(4);
alwaysTrueFalseStringCompareError(tok, str1, str2);
if (!tok->isExpandedMacro() && !tok->tokAt(2)->isExpandedMacro() && !tok->tokAt(4)->isExpandedMacro())
alwaysTrueFalseStringCompareError(tok, str1, str2);
tok = tok->tokAt(5);
} else if (Token::Match(tok->tokAt(2), "%name% , %name% ,|)")) {
const std::string &str1 = tok->strAt(2);

View File

@ -155,6 +155,16 @@ private:
"}");
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"
"{\n"
" if (stricmp(\"hotdog\",\"HOTdog\") == 0)"