From a31db92918486d529a04205b0db3081732c688e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 3 Oct 2018 13:00:11 +0200 Subject: [PATCH] Fixed #8669 (operator>> causes wrong style message) --- lib/checkclass.cpp | 4 ++++ test/testclass.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) 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