* Fix FN cstyleCast when taking address * Fix #11576 FP comparePointers with member variable * Use getParentLifetime() * Fix test case number
This commit is contained in:
parent
9b62caf0ef
commit
fb88883813
|
@ -303,7 +303,7 @@ void CheckOther::warningOldStylePointerCast()
|
||||||
tok = scope->bodyStart;
|
tok = scope->bodyStart;
|
||||||
for (; tok && tok != scope->bodyEnd; tok = tok->next()) {
|
for (; tok && tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
// Old style pointer casting..
|
// Old style pointer casting..
|
||||||
if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * *| *| const|&| ) (| %name%|%num%|%bool%|%char%|%str%"))
|
if (!Token::Match(tok, "( const|volatile| const|volatile|class|struct| %type% * *| *| const|&| ) (| %name%|%num%|%bool%|%char%|%str%|&"))
|
||||||
continue;
|
continue;
|
||||||
if (Token::Match(tok->previous(), "%type%"))
|
if (Token::Match(tok->previous(), "%type%"))
|
||||||
continue;
|
continue;
|
||||||
|
@ -3685,6 +3685,12 @@ void CheckOther::checkComparePointers()
|
||||||
continue;
|
continue;
|
||||||
if (var1->isRValueReference() || var2->isRValueReference())
|
if (var1->isRValueReference() || var2->isRValueReference())
|
||||||
continue;
|
continue;
|
||||||
|
if (const Token* parent2 = getParentLifetime(mTokenizer->isCPP(), v2.tokvalue, &mSettings->library))
|
||||||
|
if (var1 == parent2->variable())
|
||||||
|
continue;
|
||||||
|
if (const Token* parent1 = getParentLifetime(mTokenizer->isCPP(), v1.tokvalue, &mSettings->library))
|
||||||
|
if (var2 == parent1->variable())
|
||||||
|
continue;
|
||||||
comparePointersError(tok, &v1, &v2);
|
comparePointersError(tok, &v1, &v2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2653,7 +2653,7 @@ private:
|
||||||
" U* y = (U*)(&x)\n"
|
" U* y = (U*)(&x)\n"
|
||||||
" y->mutate();\n" //to avoid warnings that y can be const
|
" y->mutate();\n" //to avoid warnings that y can be const
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
||||||
|
|
||||||
check("struct C { void f() const; };\n" // #9875 - crash
|
check("struct C { void f() const; };\n" // #9875 - crash
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -5159,7 +5159,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void testMisusedScopeObjectNamespace() {
|
void testMisusedScopeObjectNamespace() {
|
||||||
check("namespace M {\n" // #4479
|
check("namespace M {\n" // #4779
|
||||||
" namespace N {\n"
|
" namespace N {\n"
|
||||||
" struct S {};\n"
|
" struct S {};\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
@ -10653,6 +10653,19 @@ private:
|
||||||
" return xp > yp;\n"
|
" return xp > yp;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("struct S { int i; };\n" // #11576
|
||||||
|
"int f(S s) {\n"
|
||||||
|
" return &s.i - (int*)&s;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (style) C-style pointer casting\n", errout.str());
|
||||||
|
|
||||||
|
check("struct S { int i; };\n"
|
||||||
|
"int f(S s1, S s2) {\n"
|
||||||
|
" return &s1.i - reinterpret_cast<int*>(&s2);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:3] -> [test.cpp:2] -> [test.cpp:3] -> [test.cpp:3]: (error) Subtracting pointers that point to different objects\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void unusedVariableValueTemplate() {
|
void unusedVariableValueTemplate() {
|
||||||
|
|
Loading…
Reference in New Issue