diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index e9cf88ff3..e6d4178f3 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -94,6 +94,8 @@ void CheckAutoVariables::autoVariables() { const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); + const bool reportWarnings(_settings->isEnabled("warning")); + const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; @@ -107,7 +109,8 @@ void CheckAutoVariables::autoVariables() const Variable * var = tok->tokAt(5)->variable(); if (checkRvalueExpression(var, tok->tokAt(6))) errorAutoVariableAssignment(tok->next(), false); - } else if (Token::Match(tok, "[;{}] %var% =") && + } else if (reportWarnings && + Token::Match(tok, "[;{}] %var% =") && isPtrArg(tok->next()) && Token::Match(tok->next()->variable()->typeStartToken(), "struct| %type% * %var% [,)]") && !pointerIsDereferencedInScope(tok->next()->variable(), scope)) { diff --git a/lib/settings.cpp b/lib/settings.cpp index 1abb685ab..db0b45240 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -75,6 +75,7 @@ std::string Settings::addEnabled(const std::string &str) static std::set id; if (id.empty()) { + id.insert("warning"); id.insert("style"); id.insert("performance"); id.insert("portability"); diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index e3f1d31b4..e0a92f7fa 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -40,6 +40,7 @@ private: Settings settings; settings.inconclusive = inconclusive; + settings.addEnabled("warning"); // Tokenize.. Tokenizer tokenizer(&settings, this);