Fixed #3749 (false positive: same expression on both sides of operator)

This commit is contained in:
Daniel Marjamäki 2012-05-17 07:26:57 +02:00
parent 505aa6e4cc
commit f803a18d50
2 changed files with 20 additions and 0 deletions

View File

@ -3046,9 +3046,20 @@ void CheckOther::checkDuplicateExpression()
}
}
// If either variable token is an expanded macro then
// don't write the warning
if (tok->next()->isExpandedMacro() || tok->tokAt(3)->isExpandedMacro())
continue;
duplicateExpressionError(tok->next(), tok->tokAt(3), tok->strAt(2));
} else if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% . %var% ==|!=|<=|>=|<|>|- %var% . %var% )|&&|%oror%|;|,") &&
tok->strAt(1) == tok->strAt(5) && tok->strAt(3) == tok->strAt(7)) {
// If either variable token is an expanded macro then
// don't write the warning
if (tok->next()->isExpandedMacro() || tok->tokAt(6)->isExpandedMacro())
continue;
duplicateExpressionError(tok->next(), tok->tokAt(6), tok->strAt(4));
}
}

View File

@ -153,6 +153,7 @@ private:
TEST_CASE(duplicateExpression2); // ticket #2730
TEST_CASE(duplicateExpression3); // ticket #3317
TEST_CASE(duplicateExpression4); // ticket #3354 (++)
TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)
TEST_CASE(alwaysTrueFalseStringCompare);
TEST_CASE(checkPointerSizeof);
@ -4218,6 +4219,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void duplicateExpression5() { // #3749 - macros with same values
Preprocessor::macroChar = '$';
check("void f() {\n"
" if ($a == $a) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueFalseStringCompare() {
check_preprocess_suppress(
"#define MACRO \"00FF00\"\n"