From d360c01675103d2e76c1def7168dfb27496978d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 9 Apr 2010 19:15:39 +0200 Subject: [PATCH] Fixed #1579 (False positive: function can be const when return type is unknown) --- lib/checkclass.cpp | 24 +++++++++++++++++++++--- test/testclass.cpp | 6 ++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 0ec51c6cf..4e26b7e3d 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1562,9 +1562,27 @@ void CheckClass::checkConst() if (Token::Match(tok2, "static|virtual")) continue; - // don't warn if type is LP.. - if (tok2->str().compare(0, 2, "LP") == 0) - continue; + // don't warn for unknown types.. + // LPVOID, HDC, etc + if (tok2->isName()) + { + bool allupper = true; + const std::string s(tok2->str()); + for (std::string::size_type pos = 0; pos < s.size(); ++pos) + { + unsigned char ch = s[pos]; + if (ch != '_' && + !std::isupper(ch) && + !std::isdigit(ch)) + { + allupper = false; + break; + } + } + + if (allupper) + continue; + } // member function? if (isMemberFunc(tok2)) diff --git a/test/testclass.cpp b/test/testclass.cpp index 4f68b1bbe..73b0b4fea 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3256,6 +3256,12 @@ private: " LPVOID a() { return 0; };\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + // #1579 - HDC + checkConst("class Fred {\n" + " HDC a() { return 0; };\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } };