Fixed #5560 (false positive: C-style pointer casting)
This commit is contained in:
parent
648479d909
commit
fc24d491cc
|
@ -480,7 +480,10 @@ void CheckOther::warningOldStylePointerCast()
|
|||
if (!_settings->isEnabled("style") || !_tokenizer->isCPP())
|
||||
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..
|
||||
if (!Token::Match(tok, "( const| %type% * ) (| %var%") &&
|
||||
!Token::Match(tok, "( const| %type% * ) (| new"))
|
||||
|
@ -497,6 +500,7 @@ void CheckOther::warningOldStylePointerCast()
|
|||
cstyleCastError(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOther::cstyleCastError(const Token *tok)
|
||||
{
|
||||
|
|
|
@ -1324,6 +1324,7 @@ private:
|
|||
|
||||
Settings settings;
|
||||
settings.addEnabled("style");
|
||||
settings.standards.cpp = Standards::CPP03; // #5560
|
||||
|
||||
// Tokenize..
|
||||
Tokenizer tokenizerCpp(&settings, this);
|
||||
|
@ -1390,6 +1391,16 @@ private:
|
|||
" virtual void abc(const B *) const = 0;\n"
|
||||
"}");
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue