diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 049c020bf..7300b8e29 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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() == "&") { diff --git a/test/testclass.cpp b/test/testclass.cpp index 82d559000..a5db98b02 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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"