assign function parameters: only show warning when --enable=warning or --enable=style is used. Ticket: #2930

This commit is contained in:
Daniel Marjamki 2013-02-02 15:08:05 +01:00
parent 082c48d557
commit 6bb8dd605a
3 changed files with 6 additions and 1 deletions

View File

@ -94,6 +94,8 @@ void CheckAutoVariables::autoVariables()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const bool reportWarnings(_settings->isEnabled("warning"));
const std::size_t functions = symbolDatabase->functionScopes.size(); const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) { for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
@ -107,7 +109,8 @@ void CheckAutoVariables::autoVariables()
const Variable * var = tok->tokAt(5)->variable(); const Variable * var = tok->tokAt(5)->variable();
if (checkRvalueExpression(var, tok->tokAt(6))) if (checkRvalueExpression(var, tok->tokAt(6)))
errorAutoVariableAssignment(tok->next(), false); errorAutoVariableAssignment(tok->next(), false);
} else if (Token::Match(tok, "[;{}] %var% =") && } else if (reportWarnings &&
Token::Match(tok, "[;{}] %var% =") &&
isPtrArg(tok->next()) && isPtrArg(tok->next()) &&
Token::Match(tok->next()->variable()->typeStartToken(), "struct| %type% * %var% [,)]") && Token::Match(tok->next()->variable()->typeStartToken(), "struct| %type% * %var% [,)]") &&
!pointerIsDereferencedInScope(tok->next()->variable(), scope)) { !pointerIsDereferencedInScope(tok->next()->variable(), scope)) {

View File

@ -75,6 +75,7 @@ std::string Settings::addEnabled(const std::string &str)
static std::set<std::string> id; static std::set<std::string> id;
if (id.empty()) { if (id.empty()) {
id.insert("warning");
id.insert("style"); id.insert("style");
id.insert("performance"); id.insert("performance");
id.insert("portability"); id.insert("portability");

View File

@ -40,6 +40,7 @@ private:
Settings settings; Settings settings;
settings.inconclusive = inconclusive; settings.inconclusive = inconclusive;
settings.addEnabled("warning");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);