Fixed #6471 (FP functionConst - member function modifying member variable after cast (inconclusive))
This commit is contained in:
parent
5164d87a2e
commit
a49d277e0d
|
@ -1991,6 +1991,9 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
|||
if (tok1->str() == "this" && tok1->previous()->isAssignmentOp())
|
||||
return false;
|
||||
|
||||
// non const pointer cast
|
||||
if (tok1->valueType() && tok1->valueType()->pointer > 0 && tok1->astParent() && tok1->astParent()->isCast() && !Token::simpleMatch(tok1->astParent(), "( const"))
|
||||
return false;
|
||||
|
||||
const Token* lhs = tok1->previous();
|
||||
if (lhs->str() == "&") {
|
||||
|
|
|
@ -170,6 +170,7 @@ private:
|
|||
TEST_CASE(const65); // ticket #8693
|
||||
TEST_CASE(const66); // ticket #7714
|
||||
TEST_CASE(const67); // ticket #9193
|
||||
TEST_CASE(const68); // ticket #6471
|
||||
TEST_CASE(const_handleDefaultParameters);
|
||||
TEST_CASE(const_passThisToMemberOfOtherClass);
|
||||
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
||||
|
@ -5514,6 +5515,17 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:8]: (style, inconclusive) Technically the member function 'Test::get' can be const.\n", errout.str());
|
||||
}
|
||||
|
||||
void const68() { // #6471
|
||||
checkConst("class MyClass {\n"
|
||||
" void clear() {\n"
|
||||
" SVecPtr v = (SVecPtr) m_data;\n"
|
||||
" v->clear();\n"
|
||||
" }\n"
|
||||
" void* m_data;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void const_handleDefaultParameters() {
|
||||
checkConst("struct Foo {\n"
|
||||
" void foo1(int i, int j = 0) {\n"
|
||||
|
|
Loading…
Reference in New Issue