Fixed #5560 (false positive: C-style pointer casting)

This commit is contained in:
Daniel Marjamäki 2014-04-29 06:21:30 +02:00
parent 648479d909
commit fc24d491cc
2 changed files with 27 additions and 12 deletions

View File

@ -480,7 +480,10 @@ void CheckOther::warningOldStylePointerCast()
if (!_settings->isEnabled("style") || !_tokenizer->isCPP()) if (!_settings->isEnabled("style") || !_tokenizer->isCPP())
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
// Old style pointer casting.. // Old style pointer casting..
if (!Token::Match(tok, "( const| %type% * ) (| %var%") && if (!Token::Match(tok, "( const| %type% * ) (| %var%") &&
!Token::Match(tok, "( const| %type% * ) (| new")) !Token::Match(tok, "( const| %type% * ) (| new"))
@ -497,6 +500,7 @@ void CheckOther::warningOldStylePointerCast()
cstyleCastError(tok); cstyleCastError(tok);
} }
} }
}
void CheckOther::cstyleCastError(const Token *tok) void CheckOther::cstyleCastError(const Token *tok)
{ {

View File

@ -1324,6 +1324,7 @@ private:
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("style");
settings.standards.cpp = Standards::CPP03; // #5560
// Tokenize.. // Tokenize..
Tokenizer tokenizerCpp(&settings, this); Tokenizer tokenizerCpp(&settings, this);
@ -1390,6 +1391,16 @@ private:
" virtual void abc(const B *) const = 0;\n" " virtual void abc(const B *) const = 0;\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #5560
checkOldStylePointerCast("class C;\n"
"\n"
"class B\n"
"{ virtual G* createGui(S*, C*) const = 0; };\n"
"\n"
"class MS : public M\n"
"{ virtual void addController(C*) override {} };");
ASSERT_EQUALS("", errout.str());
} }
void checkInvalidPointerCast(const char code[], bool portability = false, bool inconclusive = false) { void checkInvalidPointerCast(const char code[], bool portability = false, bool inconclusive = false) {