From f803a18d5017bc5e2a5541c830f4a2c3c6831c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 17 May 2012 07:26:57 +0200 Subject: [PATCH] Fixed #3749 (false positive: same expression on both sides of operator) --- lib/checkother.cpp | 11 +++++++++++ test/testother.cpp | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2d950f3b9..9afc56051 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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)); } } diff --git a/test/testother.cpp b/test/testother.cpp index 3a159be53..bef1867fd 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"