redundantAssignment: change from severity 'performance' to 'style' since avoiding unneccessary stores is a basic optimization done by compilers.

This commit is contained in:
Matthias Krüger 2016-01-15 22:01:40 +01:00
parent bb6880919c
commit 7b1710a44f
2 changed files with 22 additions and 22 deletions

View File

@ -651,11 +651,11 @@ void CheckOther::redundantAssignmentError(const Token *tok1, const Token* tok2,
{ {
const std::list<const Token *> callstack = make_container< std::list<const Token *> >() << tok1 << tok2; const std::list<const Token *> callstack = make_container< std::list<const Token *> >() << tok1 << tok2;
if (inconclusive) if (inconclusive)
reportError(callstack, Severity::performance, "redundantAssignment", reportError(callstack, Severity::style, "redundantAssignment",
"Variable '" + var + "' is reassigned a value before the old one has been used if variable is no semaphore variable.\n" "Variable '" + var + "' is reassigned a value before the old one has been used if variable is no semaphore variable.\n"
"Variable '" + var + "' is reassigned a value before the old one has been used. Make sure that this variable is not used like a semaphore in a threading environment before simplifying this code.", 0U, true); "Variable '" + var + "' is reassigned a value before the old one has been used. Make sure that this variable is not used like a semaphore in a threading environment before simplifying this code.", 0U, true);
else else
reportError(callstack, Severity::performance, "redundantAssignment", reportError(callstack, Severity::style, "redundantAssignment",
"Variable '" + var + "' is reassigned a value before the old one has been used."); "Variable '" + var + "' is reassigned a value before the old one has been used.");
} }

View File

@ -4857,7 +4857,7 @@ private:
" i = 1;\n" " i = 1;\n"
" i = 1;\n" " i = 1;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
{ {
// non-local variable => only show warning when inconclusive is used // non-local variable => only show warning when inconclusive is used
@ -4869,7 +4869,7 @@ private:
check(code, "test.cpp", false, false); // inconclusive = false check(code, "test.cpp", false, false); // inconclusive = false
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check(code, "test.cpp", false, true); // inconclusive = true check(code, "test.cpp", false, true); // inconclusive = true
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'i' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Variable 'i' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str());
} }
check("void f() {\n" check("void f() {\n"
@ -4877,14 +4877,14 @@ private:
" i = 1;\n" " i = 1;\n"
" i = 1;\n" " i = 1;\n"
"}", nullptr, false, false, false); "}", nullptr, false, false, false);
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("void f() {\n" check("void f() {\n"
" static int i;\n" " static int i;\n"
" i = 1;\n" " i = 1;\n"
" i = 1;\n" " i = 1;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'i' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Variable 'i' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str());
// Testing different types // Testing different types
check("void f() {\n" check("void f() {\n"
@ -4898,7 +4898,7 @@ private:
" bar = x;\n" " bar = x;\n"
" bar = y;\n" " bar = y;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance, inconclusive) Variable 'bar' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style, inconclusive) Variable 'bar' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str());
check("void f() {\n" check("void f() {\n"
" Foo& bar = foo();\n" // #4425. bar might refer to something global, etc. " Foo& bar = foo();\n" // #4425. bar might refer to something global, etc.
@ -4914,7 +4914,7 @@ private:
" bar();\n" " bar();\n"
" i = 1;\n" " i = 1;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("int i;\n" check("int i;\n"
"void f() {\n" "void f() {\n"
@ -4938,7 +4938,7 @@ private:
" bar();\n" " bar();\n"
" i = 1;\n" " i = 1;\n"
"}", nullptr, false, false, false); "}", nullptr, false, false, false);
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("void bar(int i) {}\n" check("void bar(int i) {}\n"
"void f(int i) {\n" "void f(int i) {\n"
@ -4969,7 +4969,7 @@ private:
" i = 1;\n" " i = 1;\n"
" i = 2;\n" " i = 2;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
// #4513 // #4513
check("int x;\n" check("int x;\n"
@ -4989,7 +4989,7 @@ private:
" x = 2;\n" " x = 2;\n"
" x = g();\n" " x = g();\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6]: (performance) Variable 'x' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6]: (style) Variable 'x' is reassigned a value before the old one has been used.\n", errout.str());
check("void f() {\n" check("void f() {\n"
" Foo& bar = foo();\n" " Foo& bar = foo();\n"
@ -5020,7 +5020,7 @@ private:
" x = 2;\n" " x = 2;\n"
" x = z.g();\n" " 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()); ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:9]: (style, 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) // from #3103 (avoid a false negative)
check("int foo(){\n" check("int foo(){\n"
@ -5029,7 +5029,7 @@ private:
" x = 1;\n" " x = 1;\n"
" return x + 1;\n" " return x + 1;\n"
"}", nullptr, false, false, false); "}", nullptr, false, false, false);
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()); ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'x' is reassigned a value before the old one has been used.\n", errout.str());
// from #3103 (avoid a false positive) // from #3103 (avoid a false positive)
check("int foo(){\n" check("int foo(){\n"
@ -5051,13 +5051,13 @@ private:
" int i = 54;\n" " int i = 54;\n"
" i = 0;\n" " i = 0;\n"
"}", 0, false, false, false); "}", 0, false, false, false);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("void f() {\n" check("void f() {\n"
" int i = 54;\n" " int i = 54;\n"
" i = 1;\n" " i = 1;\n"
"}", 0, false, false, false); "}", 0, false, false, false);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (style) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("int foo() {\n" // #4420 check("int foo() {\n" // #4420
" int x;\n" " int x;\n"
@ -5076,7 +5076,7 @@ private:
" ab.a = 2;\n" " ab.a = 2;\n"
" return ab.a;\n" " return ab.a;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6]: (performance, inconclusive) Variable 'a' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:6]: (style, inconclusive) Variable 'a' is reassigned a value before the old one has been used if variable is no semaphore variable.\n", errout.str());
check("struct AB { int a; int b; };\n" check("struct AB { int a; int b; };\n"
"\n" "\n"
@ -5188,7 +5188,7 @@ private:
" barney(x);\n" " barney(x);\n"
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (performance) Variable 'p' is reassigned a value before the old one has been used.\n" ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:5]: (style) Variable 'p' is reassigned a value before the old one has been used.\n"
"[test.cpp:2]: (style) The scope of the variable 'p' can be reduced.\n", errout.str()); "[test.cpp:2]: (style) The scope of the variable 'p' can be reduced.\n", errout.str());
check("void foo() {\n" check("void foo() {\n"
@ -5213,7 +5213,7 @@ private:
" if (memptr)\n" " if (memptr)\n"
" memptr = 0;\n" " memptr = 0;\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (performance) Variable 'memptr' is reassigned a value before the old one has been used.\n", errout.str()); 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());
} }
void redundantVarAssignment_7133() { void redundantVarAssignment_7133() {
@ -5237,7 +5237,7 @@ private:
" }\n" " }\n"
"}", "test.cpp", false, true); "}", "test.cpp", false, true);
TODO_ASSERT_EQUALS("", TODO_ASSERT_EQUALS("",
"[test.cpp:6] -> [test.cpp:9]: (performance) Variable 'Name' is reassigned a value before the old one has been used.\n", "[test.cpp:6] -> [test.cpp:9]: (style) Variable 'Name' is reassigned a value before the old one has been used.\n",
errout.str()); errout.str());
check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n"
@ -5247,7 +5247,7 @@ private:
" aSrcBuf.mnBitCount = nDestBits;\n" " aSrcBuf.mnBitCount = nDestBits;\n"
" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n"
"}", "test.c"); "}", "test.c");
ASSERT_EQUALS("[test.c:3] -> [test.c:5]: (performance) Variable 'mnBitCount' is reassigned a value before the old one has been used.\n", errout.str()); ASSERT_EQUALS("[test.c:3] -> [test.c:5]: (style) Variable 'mnBitCount' is reassigned a value before the old one has been used.\n", errout.str());
check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n"
"BitmapBuffer aSrcBuf;\n" "BitmapBuffer aSrcBuf;\n"
" aSrcBuf.mnBitCount = nSrcBits;\n" " aSrcBuf.mnBitCount = nSrcBits;\n"
@ -5255,8 +5255,8 @@ private:
" aSrcBuf.mnBitCount = nDestBits;\n" " aSrcBuf.mnBitCount = nDestBits;\n"
" bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n"
"}"); "}");
TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (performance, inconclusive) Variable 'mnBitCount' is reassigned a value before the old one has been used.\n", TODO_ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style, inconclusive) Variable 'mnBitCount' is reassigned a value before the old one has been used.\n",
"[test.cpp:3] -> [test.cpp:5]: (performance) Variable 'mnBitCount' is reassigned a value before the old one has been used.\n", "[test.cpp:3] -> [test.cpp:5]: (style) Variable 'mnBitCount' is reassigned a value before the old one has been used.\n",
errout.str()); errout.str());
} }