fix #3149 (false negative: Technically the member function 'A::f' can be const.)
This commit is contained in:
parent
ac942c6684
commit
556d523e4f
|
@ -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") || tok1->isStandardType()))
|
||||
!(Token::Match(tok1, "return|c_str|if|string|switch|while") || tok1->isStandardType()))
|
||||
{
|
||||
if (!isConstMemberFunc(scope, tok1))
|
||||
{
|
||||
|
|
|
@ -185,6 +185,7 @@ private:
|
|||
TEST_CASE(const52); // ticket #3049
|
||||
TEST_CASE(const53); // ticket #3052
|
||||
TEST_CASE(const54);
|
||||
TEST_CASE(const55); // ticket #3149
|
||||
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
||||
TEST_CASE(assigningArrayElementIsNotAConstOperation);
|
||||
TEST_CASE(constoperator1); // operator< can often be const
|
||||
|
@ -5756,6 +5757,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void const55() // ticket #3149
|
||||
{
|
||||
checkConst("class MyObject {\n"
|
||||
"public:\n"
|
||||
" void foo(int x) {\n"
|
||||
" switch (x) { }\n"
|
||||
" }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (information) Technically the member function 'MyObject::foo' can be const.\n", errout.str());
|
||||
}
|
||||
|
||||
void assigningPointerToPointerIsNotAConstOperation()
|
||||
{
|
||||
checkConst("struct s\n"
|
||||
|
|
Loading…
Reference in New Issue