Fixed #1579 (False positive: function can be const when return type is unknown)

This commit is contained in:
Daniel Marjamäki 2010-04-09 19:15:39 +02:00
parent 1328a57103
commit d360c01675
2 changed files with 27 additions and 3 deletions

View File

@ -1562,9 +1562,27 @@ void CheckClass::checkConst()
if (Token::Match(tok2, "static|virtual")) if (Token::Match(tok2, "static|virtual"))
continue; continue;
// don't warn if type is LP.. // don't warn for unknown types..
if (tok2->str().compare(0, 2, "LP") == 0) // 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; continue;
}
// member function? // member function?
if (isMemberFunc(tok2)) if (isMemberFunc(tok2))

View File

@ -3256,6 +3256,12 @@ private:
" LPVOID a() { return 0; };\n" " LPVOID a() { return 0; };\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #1579 - HDC
checkConst("class Fred {\n"
" HDC a() { return 0; };\n"
"};\n");
ASSERT_EQUALS("", errout.str());
} }
}; };