From 858d9a18a75675ab94b2848a9ae2780f0e25b2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Dec 2018 15:16:47 +0100 Subject: [PATCH] Fixed #3857 (false negative: (style) Variable 'var' is assigned a value that is never used) --- lib/astutils.cpp | 2 +- test/testother.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index c8831f743..d0a7e7b75 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1166,7 +1166,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const const Token *parent = tok; bool other = false; bool same = false; - while (Token::Match(parent->astParent(), ".|::|[")) { + while (Token::Match(parent->astParent(), "*|.|::|[")) { parent = parent->astParent(); if (parent && isSameExpression(mCpp, false, expr, parent->astOperand1(), mLibrary, false, false, nullptr)) same = true; diff --git a/test/testother.cpp b/test/testother.cpp index 02639e870..0cd9b7f7d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5969,6 +5969,21 @@ private: " memptr = 0;\n" "}"); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'memptr' is reassigned a value before the old one has been used.\n", errout.str()); + + // Pointer function argument (#3857) + check("void f(float * var)\n" + "{\n" + " var[0] = 0.2f;\n" + " var[0] = 0.2f;\n" // <-- is initialized twice + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'var[0]' is reassigned a value before the old one has been used.\n", errout.str()); + + check("void f(float * var)\n" + "{\n" + " *var = 0.2f;\n" + " *var = 0.2f;\n" // <-- is initialized twice + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable '*var' is reassigned a value before the old one has been used.\n", errout.str()); } void redundantVarAssignment_struct() {