Fixed #5560 (false positive: C-style pointer casting)
This commit is contained in:
parent
648479d909
commit
fc24d491cc
|
@ -480,21 +480,25 @@ 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();
|
||||||
// Old style pointer casting..
|
for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) {
|
||||||
if (!Token::Match(tok, "( const| %type% * ) (| %var%") &&
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
!Token::Match(tok, "( const| %type% * ) (| new"))
|
for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
continue;
|
// Old style pointer casting..
|
||||||
|
if (!Token::Match(tok, "( const| %type% * ) (| %var%") &&
|
||||||
|
!Token::Match(tok, "( const| %type% * ) (| new"))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (tok->strAt(1) == "const")
|
if (tok->strAt(1) == "const")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
if (tok->strAt(4) == "const")
|
if (tok->strAt(4) == "const")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Is "type" a class?
|
// Is "type" a class?
|
||||||
if (_tokenizer->getSymbolDatabase()->isClassOrStruct(tok->strAt(1)))
|
if (_tokenizer->getSymbolDatabase()->isClassOrStruct(tok->strAt(1)))
|
||||||
cstyleCastError(tok);
|
cstyleCastError(tok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue