From 8dd7f02e4511d9860305e168e33d9c2a0ebf4732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Feb 2014 11:02:39 +0100 Subject: [PATCH] Fixed #5381 (Some false positives that came up when using --enable=performance file.c) --- lib/checkother.cpp | 2 +- test/testother.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index addf83d7f..ac08f2855 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -669,7 +669,7 @@ void CheckOther::checkRedundantAssignment() } else if (Token::Match(tok, "break|return|continue|throw|goto")) { varAssignments.clear(); memAssignments.clear(); - } else if (tok->type() == Token::eVariable) { + } else if (tok->type() == Token::eVariable && !Token::Match(tok,"%var% (")) { // Set initialization flag if (!Token::Match(tok, "%var% [")) initialized.insert(tok->varId()); diff --git a/test/testother.cpp b/test/testother.cpp index 6531472ca..a135c8c1f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6374,6 +6374,17 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("struct AB { int a; int b; };\n" + "\n" + "int f(DO_SOMETHING do_something) {\n" + " struct AB ab;\n" + " ab.a = 1;\n" + " do_something(&ab);\n" + " ab.a = 2;\n" + " return ab.a;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("struct AB { int a; int b; };\n" "\n" "int f(struct AB *ab) {\n"