Fix ticket #413 (false positive: C-style pointer casting for pure virtual function)
http://sourceforge.net/apps/trac/cppcheck/ticket/413
This commit is contained in:
parent
ffd8008081
commit
b7171c3cd2
|
@ -48,6 +48,9 @@ void CheckOther::WarningOldStylePointerCast()
|
|||
if (!Token::Match(tok, "( %type% * ) %var%"))
|
||||
continue;
|
||||
|
||||
if (Token::simpleMatch(tok->tokAt(4), "const"))
|
||||
continue;
|
||||
|
||||
// Is "type" a class?
|
||||
const std::string pattern("class " + tok->next()->str());
|
||||
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
||||
|
|
|
@ -58,6 +58,8 @@ private:
|
|||
|
||||
TEST_CASE(nullpointer1);
|
||||
TEST_CASE(nullpointer2);
|
||||
|
||||
TEST_CASE(oldStylePointerCast);
|
||||
}
|
||||
|
||||
void check(const char code[])
|
||||
|
@ -427,6 +429,35 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkOldStylePointerCast(const char code[])
|
||||
{
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
tokenizer.setVarId();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
// Check for redundant code..
|
||||
Settings settings;
|
||||
settings._checkCodingStyle = true;
|
||||
CheckOther checkOther(&tokenizer, &settings, this);
|
||||
checkOther.WarningOldStylePointerCast();
|
||||
}
|
||||
|
||||
void oldStylePointerCast()
|
||||
{
|
||||
checkOldStylePointerCast("class B;\n"
|
||||
"class A\n"
|
||||
"{\n"
|
||||
" virtual void abc(B *) const = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestOther)
|
||||
|
|
Loading…
Reference in New Issue