diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 13bf65d27..d294a6f95 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1663,7 +1663,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Token *tok) // function call.. else if (Token::Match(tok1, "%var% (") && - !(Token::Match(tok1, "return|c_str|if|string|switch|while|catch") || tok1->isStandardType())) + !(Token::Match(tok1, "return|c_str|if|string|switch|while|catch|for") || tok1->isStandardType())) { if (!isConstMemberFunc(scope, tok1)) { diff --git a/test/testclass.cpp b/test/testclass.cpp index 93f5d104a..fd3554da4 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -5809,6 +5809,14 @@ private: " return RET_NOK;\n" "}\n"); ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (information) Technically the member function 'A::f' can be const.\n", errout.str()); + + checkConst("class MyObject {\n" + "public:\n" + " void foo(int x) {\n" + " for (int i = 0; i < 5; i++) { }\n" + " }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member function 'MyObject::foo' can be const.\n", errout.str()); } void assigningPointerToPointerIsNotAConstOperation()