diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 9b4b6e272..439afe2fb 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2071,6 +2071,10 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& return false; } + // streaming: >> *this + else if (Token::simpleMatch(tok1, ">> * this") && isLikelyStreamRead(true, tok1)) { + return false; + } // function call.. else if (Token::Match(tok1, "%name% (") && !tok1->isStandardType() && diff --git a/test/testclass.cpp b/test/testclass.cpp index 3d8842d5b..b914fc602 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -180,6 +180,7 @@ private: TEST_CASE(constoperator3); TEST_CASE(constoperator4); TEST_CASE(constoperator5); // ticket #3252 + TEST_CASE(constoperator6); // ticket #8669 TEST_CASE(constincdec); // increment/decrement => non-const TEST_CASE(constassign1); 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()); } + void constoperator6() { // ticket #8669 + checkConst("class A {\n" + " int c;\n" + " void f() { os >> *this; }\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } void const5() { // ticket #1482