From 1717bda3829408274b443fa51482836bbd67b286 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 16 Sep 2011 18:07:25 -0400 Subject: [PATCH] fix wrong information about constness of function --- lib/checkclass.cpp | 7 +++++++ test/testclass.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+) 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"