diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 529a783ae..4af712cff 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -945,9 +945,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listtokens(); tok; tok = tok->next()) { // Old style pointer casting.. - if (!Token::Match(tok, "( %type% * ) %var%")) + if (!Token::Match(tok, "( const| %type% * ) %var%")) continue; - if (Token::simpleMatch(tok->tokAt(4), "const")) + int addToIndex = 0; + if (Token::simpleMatch(tok->tokAt(1), "const")) + addToIndex = 1; + + if (Token::simpleMatch(tok->tokAt(4 + addToIndex), "const")) continue; // Is "type" a class? - const std::string pattern("class " + tok->next()->str()); + const std::string pattern("class " + tok->tokAt(1 + addToIndex)->str()); if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str())) continue; diff --git a/src/errorlogger.cpp b/src/errorlogger.cpp index e5c316075..2a22fe3d2 100644 --- a/src/errorlogger.cpp +++ b/src/errorlogger.cpp @@ -67,7 +67,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) std::string temp; for (unsigned int i = 0; i < len && iss.good(); ++i) { - char c = iss.get(); + char c = static_cast(iss.get()); temp.append(1, c); } @@ -94,7 +94,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) std::string temp; for (unsigned int i = 0; i < len && iss.good(); ++i) { - char c = iss.get(); + char c = static_cast(iss.get()); temp.append(1, c); } diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index b86f60f30..28ef9c675 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -286,7 +286,7 @@ std::string Preprocessor::read(std::istream &istr) if (ch == '\\') { char chNext = 0; - while (true) + for (;;) { chNext = (char)istr.peek(); if (chNext != '\n' && chNext != '\r' && (chNext > 0) && diff --git a/test/testother.cpp b/test/testother.cpp index 8fe279913..dbf2aaa23 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -527,6 +527,12 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str()); + checkOldStylePointerCast("class Base;\n" + "void foo()\n" + "{\n" + " Base * b = (const Base *) derived;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str()); checkOldStylePointerCast("class B;\n" "class A\n" @@ -534,6 +540,13 @@ private: " virtual void abc(B *) const = 0;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkOldStylePointerCast("class B;\n" + "class A\n" + "{\n" + " virtual void abc(const B *) const = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };