Save "->" in Token::originalName if simplified to "."; Fix false positive #4890.

This commit is contained in:
PKEuS 2014-04-12 12:01:54 +02:00
parent 9c921ab657
commit 7ffc313748
3 changed files with 16 additions and 10 deletions

View File

@ -80,6 +80,8 @@ bool isSameExpression(const Token *tok1, const Token *tok2, const std::set<std::
return false;
if (tok1->str() != tok2->str() || tok1->varId() != tok2->varId())
return false;
if (tok1->str() == "." && tok1->originalName() != tok2->originalName())
return false;
if (tok1->isExpandedMacro() || tok2->isExpandedMacro())
return false;
if (tok1->isName() && tok1->next()->str() == "(") {

View File

@ -1746,6 +1746,7 @@ void Tokenizer::combineOperators()
// replace "->" with "."
else if (c1 == '-' && c2 == '>') {
tok->str(".");
tok->originalName("->");
tok->deleteNext();
continue;
}

View File

@ -134,7 +134,6 @@ private:
TEST_CASE(incorrectLogicOperator6); // char literals
TEST_CASE(secondAlwaysTrueFalseWhenFirstTrueError);
TEST_CASE(incorrectLogicOp_condSwapping);
TEST_CASE(sameExpression);
TEST_CASE(memsetZeroBytes);
TEST_CASE(memsetInvalid2ndParam);
@ -4115,15 +4114,6 @@ private:
ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1.\n", errout.str());
}
void sameExpression() {
// #3868 - false positive (same expression on both sides of |)
check("void f(int x) {\n"
" a = x ? A | B | C\n"
" : A | B;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void memsetZeroBytes() {
check("void f() {\n"
" memset(p, 10, 0x0);\n"
@ -4729,6 +4719,19 @@ private:
// #5535: Reference named like its type
check("void foo() { UMSConfig& UMSConfig = GetUMSConfiguration(); }");
ASSERT_EQUALS("", errout.str());
// #3868 - false positive (same expression on both sides of |)
check("void f(int x) {\n"
" a = x ? A | B | C\n"
" : A | B;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" bool a = bar.isSet() && bar->isSet();\n"
" bool b = bar.isSet() && bar.isSet();\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:3]: (style) Same expression on both sides of '&&'.\n", errout.str());
}
void duplicateExpression2() { // check if float is NaN or Inf