Fixed Ticket 2144 (false negatives: Old Style Pointer Cast apply only on .cpp files)

This commit is contained in:
seb777 2011-10-26 21:17:27 +02:00
parent eda61e49c7
commit de71c41379
2 changed files with 21 additions and 2 deletions

View File

@ -276,9 +276,13 @@ void CheckOther::SuspiciousSemicolonError(const Token* tok)
//---------------------------------------------------------------------------
void CheckOther::warningOldStylePointerCast()
{
if (!_settings->isEnabled("style") ||
(_tokenizer->tokens() && _tokenizer->fileLine(_tokenizer->tokens()).find(".cpp") == std::string::npos))
if (!_settings->isEnabled("style")) {
return;
}
if (!_tokenizer->isCPP()) {
return;
}
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
// Old style pointer casting..

View File

@ -59,6 +59,21 @@ public:
return false;
}
/** Is the code C. Used for bailouts */
bool isC() const {
if (_files.size() != 1)
return false;
const std::string::size_type pos = _files[0].rfind(".");
if (pos != std::string::npos)
return (_files[0].substr(pos) == ".c");
return false;
}
/** Is the code CPP. Used for bailouts */
bool isCPP() const {
return !isJavaOrCSharp() && !isC();
}
/**
* Tokenize code
* @param code input stream for code, e.g.