Fix #10146 FP functionConst (inconclusive) with nested members (#3719)

This commit is contained in:
chrchr-github 2022-01-17 20:33:32 +01:00 committed by GitHub
parent 7406dd8c94
commit 605fd7cf98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -2210,6 +2210,8 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
return false;
tok1 = jumpBackToken?jumpBackToken:end; // Jump back to first [ to check inside, or jump to end of expression
if (tok1 == end && Token::Match(end->previous(), ". %name% ( !!)"))
tok1 = tok1->previous(); // check function call
}
// streaming: <<

View File

@ -173,6 +173,7 @@ private:
TEST_CASE(const68); // ticket #6471
TEST_CASE(const69); // ticket #9806
TEST_CASE(const70); // variadic template can receive more arguments than in its definition
TEST_CASE(const71); // ticket #10146
TEST_CASE(const_handleDefaultParameters);
TEST_CASE(const_passThisToMemberOfOtherClass);
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
@ -5772,6 +5773,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const71() { // #10146
checkConst("struct Bar {\n"
" int j = 5;\n"
" void f(int& i) const { i += j; }\n"
"};\n"
"struct Foo {\n"
" Bar bar;\n"
" int k{};\n"
" void g() { bar.f(k); }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void const_handleDefaultParameters() {
checkConst("struct Foo {\n"
" void foo1(int i, int j = 0) {\n"