Fixed #8669 (operator>> causes wrong style message)

This commit is contained in:
Daniel Marjamäki 2018-10-03 13:00:11 +02:00
parent de621eab99
commit a31db92918
2 changed files with 12 additions and 0 deletions

View File

@ -2071,6 +2071,10 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
return false; return false;
} }
// streaming: >> *this
else if (Token::simpleMatch(tok1, ">> * this") && isLikelyStreamRead(true, tok1)) {
return false;
}
// function call.. // function call..
else if (Token::Match(tok1, "%name% (") && !tok1->isStandardType() && else if (Token::Match(tok1, "%name% (") && !tok1->isStandardType() &&

View File

@ -180,6 +180,7 @@ private:
TEST_CASE(constoperator3); TEST_CASE(constoperator3);
TEST_CASE(constoperator4); TEST_CASE(constoperator4);
TEST_CASE(constoperator5); // ticket #3252 TEST_CASE(constoperator5); // ticket #3252
TEST_CASE(constoperator6); // ticket #8669
TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constincdec); // increment/decrement => non-const
TEST_CASE(constassign1); TEST_CASE(constassign1);
TEST_CASE(constassign2); TEST_CASE(constassign2);
@ -3684,6 +3685,13 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorint' can be const.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::operatorint' can be const.\n", errout.str());
} }
void constoperator6() { // ticket #8669
checkConst("class A {\n"
" int c;\n"
" void f() { os >> *this; }\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void const5() { void const5() {
// ticket #1482 // ticket #1482