Fixed #7028 (False positive: opposite conditions (const method modifies variable))
This commit is contained in:
parent
fb7230ce05
commit
814d2ae2a4
|
@ -112,8 +112,6 @@ static bool isParameterChanged(const Token *partok)
|
||||||
ftok = ftok ? ftok->previous() : nullptr;
|
ftok = ftok ? ftok->previous() : nullptr;
|
||||||
if (!(ftok && ftok->function()))
|
if (!(ftok && ftok->function()))
|
||||||
return true;
|
return true;
|
||||||
if (ftok->function()->isConst())
|
|
||||||
return false;
|
|
||||||
const Variable *par = ftok->function()->getArgumentVar(argumentNumber);
|
const Variable *par = ftok->function()->getArgumentVar(argumentNumber);
|
||||||
if (!par)
|
if (!par)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1403,6 +1403,16 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
|
||||||
|
|
||||||
|
check("void foo(const int &i);\n"
|
||||||
|
"void bar(int i) {\n"
|
||||||
|
" if(i>5) {\n"
|
||||||
|
" foo(i);\n"
|
||||||
|
" if(i<5) {\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
|
||||||
|
|
||||||
check("void foo(int i);\n"
|
check("void foo(int i);\n"
|
||||||
"void bar() {\n"
|
"void bar() {\n"
|
||||||
" int i; i = func();\n"
|
" int i; i = func();\n"
|
||||||
|
@ -1414,6 +1424,15 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (warning) Opposite conditions in nested 'if' blocks lead to a dead code block.\n", errout.str());
|
||||||
|
|
||||||
|
check("class C { void f(int &i) const; };\n" // #7028 - variable is changed by const method
|
||||||
|
"void foo(C c, int i) {\n"
|
||||||
|
" if (i==5) {\n"
|
||||||
|
" c.f(i);\n"
|
||||||
|
" if (i != 5) {}\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// see linux revision 1f80c0cc
|
// see linux revision 1f80c0cc
|
||||||
check("int generic_write_sync(int,int,int);\n"
|
check("int generic_write_sync(int,int,int);\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
Loading…
Reference in New Issue