fixed and enabled several clang-tidy warnings (#2816)

This commit is contained in:
Oliver Stöneberg 2021-01-02 19:10:25 +01:00 committed by GitHub
parent f816cc8d48
commit fbf5858f76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 30 deletions

View File

@ -1,5 +1,5 @@
--- ---
Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-llvm-*,-linuxkernel-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-modernize-use-using,-readability-container-size-empty,-readability-simplify-boolean-expr,-modernize-use-override,-modernize-pass-by-value,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-misc-unused-using-decls,-modernize-use-emplace,-readability-const-return-type,-performance-unnecessary-value-param,-readability-static-accessed-through-instance,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-performance-for-range-copy,-misc-throw-by-value-catch-by-reference,-modernize-use-bool-literals,-readability-avoid-const-params-in-decls,-readability-redundant-control-flow,-bugprone-argument-comment,-readability-redundant-string-cstr,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-performance-unnecessary-copy-initialization,-readability-redundant-string-init,-bugprone-suspicious-string-compare,-bugprone-use-after-move,-readability-misleading-indentation,-misc-unused-parameters-,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-llvmlibc-*' Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-llvm-*,-llvmlibc-*,-linuxkernel-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-modernize-use-using,-readability-container-size-empty,-readability-simplify-boolean-expr,-modernize-use-override,-modernize-pass-by-value,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-misc-unused-using-decls,-modernize-use-emplace,-readability-const-return-type,-performance-unnecessary-value-param,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-performance-for-range-copy,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-readability-redundant-control-flow,-bugprone-argument-comment,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-bugprone-suspicious-string-compare,-bugprone-use-after-move,-readability-misleading-indentation,-misc-unused-parameters-,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-readability-inconsistent-declaration-parameter-name'
CheckOptions: CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1' value: '1'

View File

@ -355,7 +355,7 @@ void ThreadExecutor::reportInfo(const ErrorMessage &msg)
void ThreadExecutor::bughuntingReport(const std::string &str) void ThreadExecutor::bughuntingReport(const std::string &str)
{ {
writeToPipe(REPORT_VERIFICATION, str.c_str()); writeToPipe(REPORT_VERIFICATION, str);
} }
void ThreadExecutor::reportInternalChildErr(const std::string &childname, const std::string &msg) void ThreadExecutor::reportInternalChildErr(const std::string &childname, const std::string &msg)

View File

@ -73,17 +73,17 @@ int main(int argc, char *argv[])
TranslationHandler* th = new TranslationHandler(&app); TranslationHandler* th = new TranslationHandler(&app);
th->setLanguage(settings->value(SETTINGS_LANGUAGE, th->suggestLanguage()).toString()); th->setLanguage(settings->value(SETTINGS_LANGUAGE, th->suggestLanguage()).toString());
if (!CheckArgs(app.arguments())) if (!CheckArgs(QApplication::arguments()))
return 0; return 0;
app.setWindowIcon(QIcon(":cppcheck-gui.png")); QApplication::setWindowIcon(QIcon(":cppcheck-gui.png"));
// Register this metatype that is used to transfer error info // Register this metatype that is used to transfer error info
qRegisterMetaType<ErrorItem>("ErrorItem"); qRegisterMetaType<ErrorItem>("ErrorItem");
MainWindow window(th, settings); MainWindow window(th, settings);
window.show(); window.show();
return app.exec(); return QApplication::exec();
} }
// Check only arguments needing action before GUI is shown. // Check only arguments needing action before GUI is shown.

View File

@ -1000,7 +1000,7 @@ Settings MainWindow::getCppcheckSettings()
result.jobs = 1; result.jobs = 1;
} }
result.terminate(false); Settings::terminate(false);
return result; return result;
} }

View File

@ -1104,7 +1104,7 @@ void CheckCondition::checkIncorrectLogicOperator()
const std::string cond2 = expr1; const std::string cond2 = expr1;
const std::string cond1VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr2VerboseMsg + " " + tok->astOperand2()->str() + " " + expr3VerboseMsg; const std::string cond1VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr2VerboseMsg + " " + tok->astOperand2()->str() + " " + expr3VerboseMsg;
const std::string cond2VerboseMsg = expr1VerboseMsg; const std::string& cond2VerboseMsg = expr1VerboseMsg;
// for the --verbose message, transform the actual condition and print it // for the --verbose message, transform the actual condition and print it
const std::string msg = tok2->expressionString() + ". '" + cond1 + "' is equivalent to '" + cond2 + "'\n" const std::string msg = tok2->expressionString() + ". '" + cond1 + "' is equivalent to '" + cond2 + "'\n"
"The condition '" + cond1VerboseMsg + "' is equivalent to '" + cond2VerboseMsg + "'."; "The condition '" + cond1VerboseMsg + "' is equivalent to '" + cond2VerboseMsg + "'.";

View File

@ -88,7 +88,7 @@ namespace {
} }
std::string parseAddonInfo(const picojson::value &json, const std::string &fileName, const std::string &exename) { std::string parseAddonInfo(const picojson::value &json, const std::string &fileName, const std::string &exename) {
std::string json_error = picojson::get_last_error(); const std::string& json_error = picojson::get_last_error();
if (!json_error.empty()) { if (!json_error.empty()) {
return "Loading " + fileName + " failed. " + json_error; return "Loading " + fileName + " failed. " + json_error;
} }
@ -1434,7 +1434,7 @@ void CppCheck::getErrorMessages()
void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings) void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
{ {
std::string allIncludes = ""; std::string allIncludes;
for (const std::string &inc : fileSettings.includePaths) { for (const std::string &inc : fileSettings.includePaths) {
allIncludes = allIncludes + "-I\"" + inc + "\" "; allIncludes = allIncludes + "-I\"" + inc + "\" ";
} }

View File

@ -2388,13 +2388,13 @@ static ExprEngine::ValuePtr executeNumber(const Token *tok, Data &data)
static ExprEngine::ValuePtr executeStringLiteral(const Token *tok, Data &data) static ExprEngine::ValuePtr executeStringLiteral(const Token *tok, Data &data)
{ {
std::string s = tok->str(); const std::string& s = tok->str();
return std::make_shared<ExprEngine::StringLiteralValue>(data.getNewSymbolName(), s.substr(1, s.size()-2)); return std::make_shared<ExprEngine::StringLiteralValue>(data.getNewSymbolName(), s.substr(1, s.size()-2));
} }
static ExprEngine::ValuePtr executeExpression1(const Token *tok, Data &data) static ExprEngine::ValuePtr executeExpression1(const Token *tok, Data &data)
{ {
if (data.settings->terminated()) if (Settings::terminated())
throw TerminateExpression(); throw TerminateExpression();
if (tok->str() == "return") if (tok->str() == "return")

View File

@ -5583,7 +5583,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
const Token *op1 = parent->astOperand2()->astOperand1(); const Token *op1 = parent->astOperand2()->astOperand1();
while (op1 && op1->str() == "[") while (op1 && op1->str() == "[")
op1 = op1->astOperand1(); op1 = op1->astOperand1();
ValueType vt(valuetype); const ValueType& vt(valuetype);
if (op1 && op1->variable() && op1->variable()->nameToken() == op1) { if (op1 && op1->variable() && op1->variable()->nameToken() == op1) {
setValueType(parent, vt); setValueType(parent, vt);
return; return;

View File

@ -1509,7 +1509,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c
bool TemplateSimplifier::alreadyHasNamespace(const TokenAndName &templateDeclaration, const Token *tok) bool TemplateSimplifier::alreadyHasNamespace(const TokenAndName &templateDeclaration, const Token *tok)
{ {
std::string scope = templateDeclaration.scope(); const std::string& scope = templateDeclaration.scope();
// get the length in tokens of the namespace // get the length in tokens of the namespace
std::string::size_type pos = 0; std::string::size_type pos = 0;

View File

@ -5170,7 +5170,7 @@ void Tokenizer::simplifyHeadersAndUnusedTemplates()
if (!tok->previous() || Token::Match(tok->previous(), "[;{}]")) { if (!tok->previous() || Token::Match(tok->previous(), "[;{}]")) {
// Remove unused function declarations // Remove unused function declarations
if (isIncluded && removeUnusedIncludedFunctions) { if (isIncluded && removeUnusedIncludedFunctions) {
while (1) { while (true) {
Token *start = tok; Token *start = tok;
while (start && functionStart.find(start->str()) != functionStart.end()) while (start && functionStart.find(start->str()) != functionStart.end())
start = start->next(); start = start->next();
@ -9856,7 +9856,7 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok); syntaxError(tok);
} }
if (Token::Match(tok, "%or%|%oror%|~|^|!|%comp%|+|-|/|%")) { if (Token::Match(tok, "%or%|%oror%|~|^|!|%comp%|+|-|/|%")) {
std::string code = ""; std::string code;
if (Token::Match(tok->next(), ")|]|}")) if (Token::Match(tok->next(), ")|]|}"))
code = tok->str() + tok->next()->str(); code = tok->str() + tok->next()->str();
if (Token::simpleMatch(tok->next(), "( )")) if (Token::simpleMatch(tok->next(), "( )"))

View File

@ -559,33 +559,32 @@ private:
} }
void multi_inlinesuppress() { void multi_inlinesuppress() {
Suppressions ss;
std::vector<Suppressions::Suppression> suppressions; std::vector<Suppressions::Suppression> suppressions;
std::string errMsg; std::string errMsg;
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId]", &errMsg);
ASSERT_EQUALS(1, suppressions.size()); ASSERT_EQUALS(1, suppressions.size());
ASSERT_EQUALS("errorId", suppressions[0].errorId); ASSERT_EQUALS("errorId", suppressions[0].errorId);
ASSERT_EQUALS("", suppressions[0].symbolName); ASSERT_EQUALS("", suppressions[0].symbolName);
ASSERT_EQUALS("", errMsg); ASSERT_EQUALS("", errMsg);
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId symbolName=arr]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId symbolName=arr]", &errMsg);
ASSERT_EQUALS(1, suppressions.size()); ASSERT_EQUALS(1, suppressions.size());
ASSERT_EQUALS("errorId", suppressions[0].errorId); ASSERT_EQUALS("errorId", suppressions[0].errorId);
ASSERT_EQUALS("arr", suppressions[0].symbolName); ASSERT_EQUALS("arr", suppressions[0].symbolName);
ASSERT_EQUALS("", errMsg); ASSERT_EQUALS("", errMsg);
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId symbolName=]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId symbolName=]", &errMsg);
ASSERT_EQUALS(1, suppressions.size()); ASSERT_EQUALS(1, suppressions.size());
ASSERT_EQUALS("errorId", suppressions[0].errorId); ASSERT_EQUALS("errorId", suppressions[0].errorId);
ASSERT_EQUALS("", suppressions[0].symbolName); ASSERT_EQUALS("", suppressions[0].symbolName);
ASSERT_EQUALS("", errMsg); ASSERT_EQUALS("", errMsg);
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId1, errorId2 symbolName=arr]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId1, errorId2 symbolName=arr]", &errMsg);
ASSERT_EQUALS(2, suppressions.size()); ASSERT_EQUALS(2, suppressions.size());
ASSERT_EQUALS("errorId1", suppressions[0].errorId); ASSERT_EQUALS("errorId1", suppressions[0].errorId);
ASSERT_EQUALS("", suppressions[0].symbolName); ASSERT_EQUALS("", suppressions[0].symbolName);
@ -594,53 +593,52 @@ private:
ASSERT_EQUALS("", errMsg); ASSERT_EQUALS("", errMsg);
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[]", &errMsg);
ASSERT_EQUALS(0, suppressions.size()); ASSERT_EQUALS(0, suppressions.size());
ASSERT_EQUALS(true, errMsg.empty()); ASSERT_EQUALS(true, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId", &errMsg);
ASSERT_EQUALS(0, suppressions.size()); ASSERT_EQUALS(0, suppressions.size());
ASSERT_EQUALS(false, errMsg.empty()); ASSERT_EQUALS(false, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress errorId", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress errorId", &errMsg);
ASSERT_EQUALS(0, suppressions.size()); ASSERT_EQUALS(0, suppressions.size());
ASSERT_EQUALS(false, errMsg.empty()); ASSERT_EQUALS(false, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId1 errorId2 symbolName=arr]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId1 errorId2 symbolName=arr]", &errMsg);
ASSERT_EQUALS(0, suppressions.size()); ASSERT_EQUALS(0, suppressions.size());
ASSERT_EQUALS(false, errMsg.empty()); ASSERT_EQUALS(false, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId1, errorId2 symbol=arr]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId1, errorId2 symbol=arr]", &errMsg);
ASSERT_EQUALS(0, suppressions.size()); ASSERT_EQUALS(0, suppressions.size());
ASSERT_EQUALS(false, errMsg.empty()); ASSERT_EQUALS(false, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("// cppcheck-suppress[errorId1, errorId2 symbolName]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("// cppcheck-suppress[errorId1, errorId2 symbolName]", &errMsg);
ASSERT_EQUALS(0, suppressions.size()); ASSERT_EQUALS(0, suppressions.size());
ASSERT_EQUALS(false, errMsg.empty()); ASSERT_EQUALS(false, errMsg.empty());
} }
void multi_inlinesuppress_comment() { void multi_inlinesuppress_comment() {
Suppressions ss;
std::vector<Suppressions::Suppression> suppressions; std::vector<Suppressions::Suppression> suppressions;
std::string errMsg; std::string errMsg;
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("//cppcheck-suppress[errorId1, errorId2 symbolName=arr]", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("//cppcheck-suppress[errorId1, errorId2 symbolName=arr]", &errMsg);
ASSERT_EQUALS(2, suppressions.size()); ASSERT_EQUALS(2, suppressions.size());
ASSERT_EQUALS(true, errMsg.empty()); ASSERT_EQUALS(true, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("//cppcheck-suppress[errorId1, errorId2 symbolName=arr] some text", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("//cppcheck-suppress[errorId1, errorId2 symbolName=arr] some text", &errMsg);
ASSERT_EQUALS(2, suppressions.size()); ASSERT_EQUALS(2, suppressions.size());
ASSERT_EQUALS(true, errMsg.empty()); ASSERT_EQUALS(true, errMsg.empty());
errMsg = ""; errMsg = "";
suppressions=ss.parseMultiSuppressComment("/*cppcheck-suppress[errorId1, errorId2 symbolName=arr]*/", &errMsg); suppressions=Suppressions::parseMultiSuppressComment("/*cppcheck-suppress[errorId1, errorId2 symbolName=arr]*/", &errMsg);
ASSERT_EQUALS(2, suppressions.size()); ASSERT_EQUALS(2, suppressions.size());
ASSERT_EQUALS(true, errMsg.empty()); ASSERT_EQUALS(true, errMsg.empty());
} }