From 08ac48199e968e0f31c2eaa8f724ec019ad6c2a5 Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Wed, 3 Apr 2013 09:33:33 +0200 Subject: [PATCH] #3103 added testcases. --- test/testother.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index 678809cee..2dea31356 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -7098,6 +7098,25 @@ private: " x = z.g();\n" "}"); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (performance, inconclusive) Variable 'x' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); + + // from #3103 (avoid a false negative) + check("int foo(){\n" + " int x;\n" + " x = 1;\n" + " x = 1;\n" + " return x + 1;\n" + "}"); + ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Variable 'x' is reassigned a value before the old one has been used.\n", errout.str()); + + // from #3103 (avoid a false positive) + check("int foo(){\n" + " int x;\n" + " x = 1;\n" + " if (y)\n" // <-- cppcheck does not know anything about 'y' + " x = 2;\n" + " return x + 1;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void redundantMemWrite() {