* Fix #10315 FP functionConst * Update releasenotes.txt
This commit is contained in:
parent
28a024ac4a
commit
00badff622
|
@ -2207,8 +2207,12 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
if (v && v->isMutable())
|
if (v && v->isMutable())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (tok1->str() == "this" && tok1->previous()->isAssignmentOp())
|
if (tok1->str() == "this") {
|
||||||
|
if (tok1->previous()->isAssignmentOp())
|
||||||
return false;
|
return false;
|
||||||
|
if (Token::Match(tok1->previous(), "( this . * %var% )")) // call using ptr to member function TODO: check constness
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// non const pointer cast
|
// non const pointer cast
|
||||||
if (tok1->valueType() && tok1->valueType()->pointer > 0 && tok1->astParent() && tok1->astParent()->isCast() && !Token::simpleMatch(tok1->astParent(), "( const"))
|
if (tok1->valueType() && tok1->valueType()->pointer > 0 && tok1->astParent() && tok1->astParent()->isCast() && !Token::simpleMatch(tok1->astParent(), "( const"))
|
||||||
|
|
|
@ -12,3 +12,5 @@ release notes for cppcheck-2.8
|
||||||
- Detect more statements with constStatement
|
- Detect more statements with constStatement
|
||||||
- Detect variableScope for more types
|
- Detect variableScope for more types
|
||||||
- Improvements to unreadVariable
|
- Improvements to unreadVariable
|
||||||
|
- Detect more instances of C style casts
|
||||||
|
- Warn if the return value of new is discarded
|
||||||
|
|
|
@ -194,6 +194,7 @@ private:
|
||||||
TEST_CASE(const75); // ticket #10065
|
TEST_CASE(const75); // ticket #10065
|
||||||
TEST_CASE(const76); // ticket #10825
|
TEST_CASE(const76); // ticket #10825
|
||||||
TEST_CASE(const77); // ticket #10307
|
TEST_CASE(const77); // ticket #10307
|
||||||
|
TEST_CASE(const78); // ticket #10315
|
||||||
TEST_CASE(const_handleDefaultParameters);
|
TEST_CASE(const_handleDefaultParameters);
|
||||||
TEST_CASE(const_passThisToMemberOfOtherClass);
|
TEST_CASE(const_passThisToMemberOfOtherClass);
|
||||||
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
||||||
|
@ -6041,6 +6042,26 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void const78() { // #10315
|
||||||
|
checkConst("struct S {\n"
|
||||||
|
" typedef void(S::* F)();\n"
|
||||||
|
" void g(F f);\n"
|
||||||
|
"};\n"
|
||||||
|
"void S::g(F f) {\n"
|
||||||
|
" (this->*f)();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkConst("struct S {\n"
|
||||||
|
" using F = void(S::*)();\n"
|
||||||
|
" void g(F f);\n"
|
||||||
|
"};\n"
|
||||||
|
"void S::g(F f) {\n"
|
||||||
|
" (this->*f)();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void const_handleDefaultParameters() {
|
void const_handleDefaultParameters() {
|
||||||
checkConst("struct Foo {\n"
|
checkConst("struct Foo {\n"
|
||||||
" void foo1(int i, int j = 0) {\n"
|
" void foo1(int i, int j = 0) {\n"
|
||||||
|
|
Loading…
Reference in New Issue