Fixed #3749 (false positive: same expression on both sides of operator)
This commit is contained in:
parent
505aa6e4cc
commit
f803a18d50
|
@ -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));
|
duplicateExpressionError(tok->next(), tok->tokAt(3), tok->strAt(2));
|
||||||
} else if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% . %var% ==|!=|<=|>=|<|>|- %var% . %var% )|&&|%oror%|;|,") &&
|
} else if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% . %var% ==|!=|<=|>=|<|>|- %var% . %var% )|&&|%oror%|;|,") &&
|
||||||
tok->strAt(1) == tok->strAt(5) && tok->strAt(3) == tok->strAt(7)) {
|
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));
|
duplicateExpressionError(tok->next(), tok->tokAt(6), tok->strAt(4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,7 @@ private:
|
||||||
TEST_CASE(duplicateExpression2); // ticket #2730
|
TEST_CASE(duplicateExpression2); // ticket #2730
|
||||||
TEST_CASE(duplicateExpression3); // ticket #3317
|
TEST_CASE(duplicateExpression3); // ticket #3317
|
||||||
TEST_CASE(duplicateExpression4); // ticket #3354 (++)
|
TEST_CASE(duplicateExpression4); // ticket #3354 (++)
|
||||||
|
TEST_CASE(duplicateExpression5); // ticket #3749 (macros with same values)
|
||||||
|
|
||||||
TEST_CASE(alwaysTrueFalseStringCompare);
|
TEST_CASE(alwaysTrueFalseStringCompare);
|
||||||
TEST_CASE(checkPointerSizeof);
|
TEST_CASE(checkPointerSizeof);
|
||||||
|
@ -4218,6 +4219,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void alwaysTrueFalseStringCompare() {
|
||||||
check_preprocess_suppress(
|
check_preprocess_suppress(
|
||||||
"#define MACRO \"00FF00\"\n"
|
"#define MACRO \"00FF00\"\n"
|
||||||
|
|
Loading…
Reference in New Issue