Fixed #1527 (Function can't be const if it has non-const operator overload call)
This commit is contained in:
parent
93d4851040
commit
427d155644
|
@ -1902,6 +1902,13 @@ bool CheckClass::checkConstFunc(const std::string &classname, const Var *varlist
|
|||
}
|
||||
}
|
||||
|
||||
// streaming: <<
|
||||
else if (tok1->str() == "<<" && isMemberVar(classname, varlist, tok1->previous()))
|
||||
{
|
||||
isconst = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// increment/decrement (member variable?)..
|
||||
else if (Token::Match(tok1, "++|--"))
|
||||
{
|
||||
|
|
|
@ -112,7 +112,8 @@ private:
|
|||
TEST_CASE(const16); // ticket #1551
|
||||
TEST_CASE(const17); // ticket #1552
|
||||
TEST_CASE(const18); // ticket #1563
|
||||
TEST_CASE(constoperator); // operator< can often be const
|
||||
TEST_CASE(constoperator1); // operator< can often be const
|
||||
TEST_CASE(constoperator2); // operator<<
|
||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||
TEST_CASE(constReturnReference);
|
||||
TEST_CASE(constDelete); // delete member variable => not const
|
||||
|
@ -2241,7 +2242,7 @@ private:
|
|||
}
|
||||
|
||||
// operator< can often be const
|
||||
void constoperator()
|
||||
void constoperator1()
|
||||
{
|
||||
checkConst("struct Fred {\n"
|
||||
" int a;\n"
|
||||
|
@ -2250,6 +2251,22 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (style) The function 'Fred::operator<' can be const\n", errout.str());
|
||||
}
|
||||
|
||||
// operator<<
|
||||
void constoperator2()
|
||||
{
|
||||
checkConst("struct Foo {\n"
|
||||
" void operator<<(int);\n"
|
||||
"};\n"
|
||||
"struct Fred {\n"
|
||||
" Foo foo;\n"
|
||||
" void x()\n"
|
||||
" {\n"
|
||||
" foo << 123;\n"
|
||||
" }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void const5()
|
||||
{
|
||||
// ticket #1482
|
||||
|
|
Loading…
Reference in New Issue