Skip to content

Commit e47d7b5

Browse files
Fix #14702 FP functionConst (iterating over *this) (#8507)
1 parent 2945030 commit e47d7b5

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
25672567
return false;
25682568
if (Token::Match(tok1->previous(), "( this . * %var% )")) // call using ptr to member function TODO: check constness
25692569
return false;
2570-
if (Token::simpleMatch(tok1->astParent(), "*") && tok1->astParent()->astParent() && tok1->astParent()->astParent()->isIncDecOp())
2570+
if (Token::simpleMatch(tok1->astParent(), "*"))
25712571
return false;
25722572
}
25732573

test/testclass.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6974,13 +6974,28 @@ class TestClass : public TestFixture {
69746974
}
69756975

69766976
void const101() {
6977-
checkConst("struct error {\n"
6977+
checkConst("struct error {\n" // #14450
69786978
" error() = default;\n"
69796979
"};\n"
69806980
"struct S : U {\n"
69816981
" int f() { return this->error(); }\n"
69826982
"};\n");
69836983
ASSERT_EQUALS("", errout_str());
6984+
6985+
checkConst("struct S {\n" // #14702
6986+
" int i;\n"
6987+
" void f() {\n"
6988+
" S& r = *this;\n"
6989+
" r.i = 0;\n"
6990+
" }\n"
6991+
"};\n"
6992+
"struct T : std::array<int, 5> {\n"
6993+
" void g() {\n"
6994+
" for (int& r : *this)\n"
6995+
" r = 0;\n"
6996+
" }\n"
6997+
"};\n");
6998+
ASSERT_EQUALS("", errout_str());
69846999
}
69857000

69867001
void const_handleDefaultParameters() {

0 commit comments

Comments
 (0)