diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index cb59d042d..f99947609 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1606,6 +1606,13 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Token *tok) break; } + // streaming: >> + else if (tok1->str() == ">>" && isMemberVar(scope, tok1->next())) + { + isconst = false; + break; + } + // increment/decrement (member variable?).. else if (Token::Match(tok1, "++|--")) { diff --git a/test/testclass.cpp b/test/testclass.cpp index b736a70e9..4a88d3243 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -184,6 +184,7 @@ private: TEST_CASE(const51); // ticket #3040 TEST_CASE(const52); // ticket #3049 TEST_CASE(const53); // ticket #3052 + TEST_CASE(const54); TEST_CASE(assigningPointerToPointerIsNotAConstOperation); TEST_CASE(assigningArrayElementIsNotAConstOperation); TEST_CASE(constoperator1); // operator< can often be const @@ -5742,6 +5743,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void const54() + { + checkConst("class MyObject {\n" + " int tmp;\n" + " MyObject() : tmp(0) {}\n" + "public:\n" + " void set(std::stringstream &in) { in >> tmp; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void assigningPointerToPointerIsNotAConstOperation() { checkConst("struct s\n"