diff --git a/.clang-tidy b/.clang-tidy index ff8638db6..d8964d471 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,google-explicit-constructor,-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-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-misc-non-private-member-variables-in-classes,-clang-analyzer-*,-bugprone-signed-char-misuse,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness,-portability-std-allocator-const,-modernize-deprecated-ios-base-aliases,-bugprone-unchecked-optional-access,-modernize-replace-auto-ptr,-readability-identifier-naming,-portability-simd-intrinsics' +Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,google-explicit-constructor,-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-redundant-member-init,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-readability-simplify-boolean-expr,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-misc-non-private-member-variables-in-classes,-clang-analyzer-*,-bugprone-signed-char-misuse,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness,-portability-std-allocator-const,-modernize-deprecated-ios-base-aliases,-bugprone-unchecked-optional-access,-modernize-replace-auto-ptr,-readability-identifier-naming,-portability-simd-intrinsics' WarningsAsErrors: '*' HeaderFilterRegex: '(cli|gui|lib|oss-fuzz|test|triage)\/[a-z]+\.h' CheckOptions: diff --git a/clang-tidy.md b/clang-tidy.md index 2d4fbffc0..d37a7e1b9 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -58,7 +58,6 @@ These do not (always) increase readability. To be documented. -`performance-faster-string-find`
`bugprone-narrowing-conversions`
`performance-no-automatic-move`
diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 81202d54e..1f6debe2f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -581,7 +581,7 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector for (const std::string &arg : args) { if (!joinedArgs.empty()) joinedArgs += " "; - if (arg.find(" ") != std::string::npos) + if (arg.find(' ') != std::string::npos) joinedArgs += '"' + arg + '"'; else joinedArgs += arg; diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index 2eca3c2a7..de1e229eb 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -739,7 +739,7 @@ void ProjectFileDialog::addSingleSuppression(const Suppressions::Suppression &su bool found_relative = false; // Replace relative file path in the suppression with the absolute one - if ((suppression.fileName.find("*") == std::string::npos) && + if ((suppression.fileName.find('*') == std::string::npos) && (suppression.fileName.find(sep) == std::string::npos)) { QFileInfo inf(mProjectFile->getFilename()); QString rootpath = inf.absolutePath(); diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 5b3e69b2f..1baaa460d 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1447,7 +1447,7 @@ void CheckUnusedVar::checkStructMemberUsage() continue; // Bail out for template struct, members might be used in non-matching instantiations - if (scope.className.find("<") != std::string::npos) + if (scope.className.find('<') != std::string::npos) continue; // bail out if struct is inherited diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 937b60f88..a3e4de892 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -124,22 +124,22 @@ static std::string unquote(const std::string &s) static std::vector splitString(const std::string &line) { std::vector ret; - std::string::size_type pos1 = line.find_first_not_of(" "); + std::string::size_type pos1 = line.find_first_not_of(' '); while (pos1 < line.size()) { std::string::size_type pos2; if (std::strchr("*()", line[pos1])) { ret.push_back(line.substr(pos1,1)); - pos1 = line.find_first_not_of(" ", pos1 + 1); + pos1 = line.find_first_not_of(' ', pos1 + 1); continue; } if (line[pos1] == '<') - pos2 = line.find(">", pos1); + pos2 = line.find('>', pos1); else if (line[pos1] == '\"') - pos2 = line.find("\"", pos1+1); + pos2 = line.find('\"', pos1+1); else if (line[pos1] == '\'') { - pos2 = line.find("\'", pos1+1); + pos2 = line.find('\'', pos1+1); if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) - pos2 = line.find("\'", pos2 + 3); + pos2 = line.find('\'', pos2 + 3); } else { pos2 = pos1; while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum((unsigned char)line[pos2]))) @@ -159,10 +159,10 @@ static std::vector splitString(const std::string &line) } } - pos2 = line.find(" ", pos1) - 1; + pos2 = line.find(' ', pos1) - 1; if ((std::isalpha(line[pos1]) || line[pos1] == '_') && line.find("::", pos1) < pos2 && - line.find("::", pos1) < line.find("<", pos1)) { + line.find("::", pos1) < line.find('<', pos1)) { pos2 = line.find("::", pos1); ret.push_back(line.substr(pos1, pos2-pos1)); ret.emplace_back("::"); @@ -170,10 +170,10 @@ static std::vector splitString(const std::string &line) continue; } if ((std::isalpha(line[pos1]) || line[pos1] == '_') && - line.find("<", pos1) < pos2 && - line.find("<<",pos1) != line.find("<",pos1) && - line.find(">", pos1) != std::string::npos && - line.find(">", pos1) > pos2) { + line.find('<', pos1) < pos2 && + line.find("<<",pos1) != line.find('<',pos1) && + line.find('>', pos1) != std::string::npos && + line.find('>', pos1) > pos2) { int level = 0; for (pos2 = pos1; pos2 < line.size(); ++pos2) { if (line[pos2] == '<') @@ -186,7 +186,7 @@ static std::vector splitString(const std::string &line) } if (level > 1 && pos2 + 1 >= line.size()) return std::vector {}; - pos2 = line.find(" ", pos2); + pos2 = line.find(' ', pos2); if (pos2 != std::string::npos) --pos2; } @@ -196,7 +196,7 @@ static std::vector splitString(const std::string &line) break; } ret.push_back(line.substr(pos1, pos2+1-pos1)); - pos1 = line.find_first_not_of(" ", pos2 + 1); + pos1 = line.find_first_not_of(' ', pos2 + 1); } return ret; } @@ -546,8 +546,8 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s std::string type; if (str.find(" (") != std::string::npos) { - if (str.find("<") != std::string::npos) - type = str.substr(1, str.find("<")) + "...>"; + if (str.find('<') != std::string::npos) + type = str.substr(1, str.find('<')) + "...>"; else type = str.substr(1,str.find(" (")-1); } else @@ -557,8 +557,8 @@ const ::Type * clangimport::AstNode::addTypeTokens(TokenList *tokenList, const s type.erase(type.find("(*)(")); type += "*"; } - if (type.find("(") != std::string::npos) - type.erase(type.find("(")); + if (type.find('(') != std::string::npos) + type.erase(type.find('(')); std::stack lpar; for (const std::string &s: splitString(type)) { @@ -620,7 +620,7 @@ void clangimport::AstNode::setValueType(Token *tok) for (int i = 0; i < 2; i++) { const std::string &type = getType(i); - if (type.find("<") != std::string::npos) + if (type.find('<') != std::string::npos) // TODO continue; @@ -897,8 +897,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) return newtok; } std::string type = getType(); - if (type.find("*") != std::string::npos) - type = type.erase(type.rfind("*")); + if (type.find('*') != std::string::npos) + type = type.erase(type.rfind('*')); addTypeTokens(tokenList, type); if (!children.empty()) { Token *bracket1 = addtoken(tokenList, "["); @@ -1577,7 +1577,7 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f) std::string line; std::vector tree; while (std::getline(f,line)) { - const std::string::size_type pos1 = line.find("-"); + const std::string::size_type pos1 = line.find('-'); if (pos1 == std::string::npos) continue; if (!tree.empty() && line.substr(pos1) == "-<<>>") { @@ -1585,7 +1585,7 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f) tree[level - 1]->children.push_back(nullptr); continue; } - const std::string::size_type pos2 = line.find(" ", pos1); + const std::string::size_type pos2 = line.find(' ', pos1); if (pos2 < pos1 + 4 || pos2 == std::string::npos) continue; const std::string nodeType = line.substr(pos1+1, pos2 - pos1 - 1); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a3f387b2e..55749b9d8 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -162,7 +162,7 @@ namespace { in >> json; return parseAddonInfo(json, fileName, exename); } - if (fileName.find(".") == std::string::npos) + if (fileName.find('.') == std::string::npos) return getAddonInfo(fileName + ".py", exename); if (endsWith(fileName, ".py")) { @@ -170,12 +170,12 @@ namespace { if (scriptFile.empty()) return "Did not find addon " + fileName; - std::string::size_type pos1 = scriptFile.rfind("/"); + std::string::size_type pos1 = scriptFile.rfind('/'); if (pos1 == std::string::npos) pos1 = 0; else pos1++; - std::string::size_type pos2 = scriptFile.rfind("."); + std::string::size_type pos2 = scriptFile.rfind('.'); if (pos2 < pos1) pos2 = std::string::npos; name = scriptFile.substr(pos1, pos2 - pos1); @@ -201,7 +201,7 @@ namespace { static std::string cmdFileName(std::string f) { f = Path::toNativeSeparators(f); - if (f.find(" ") != std::string::npos) + if (f.find(' ') != std::string::npos) return "\"" + f + "\""; return f; } @@ -215,7 +215,7 @@ static std::vector split(const std::string &str, const std::string break; if (str[startPos] == '\"') { - const std::string::size_type endPos = str.find("\"", startPos + 1); + const std::string::size_type endPos = str.find('\"', startPos + 1); ret.push_back(str.substr(startPos + 1, endPos - startPos - 1)); startPos = (endPos < str.size()) ? (endPos + 1) : endPos; continue; @@ -415,8 +415,8 @@ static bool reportClangErrors(std::istream &is, const std::function= pos2 || pos2 >= pos3) continue; @@ -424,7 +424,7 @@ static bool reportClangErrors(std::istream &is, const std::functionisName() && Token::Match(tok, "%name% (") && tok->str().find("<") != std::string::npos && tok->str().find(expr->str()) != std::string::npos) + if (expr->isName() && Token::Match(tok, "%name% (") && tok->str().find('<') != std::string::npos && tok->str().find(expr->str()) != std::string::npos) return Result(Result::Type::BAILOUT); if (exprVarIds.find(tok->varId()) != exprVarIds.end()) { diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 164c861ea..0932db71a 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -393,7 +393,7 @@ bool ImportProject::importCompileCommands(std::istream &istr) for (const picojson::value& arg : obj["arguments"].get()) { if (arg.is()) { std::string str = arg.get(); - if (str.find(" ") != std::string::npos) + if (str.find(' ') != std::string::npos) str = "\"" + str + "\""; command += str + " "; } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index b329a82e7..ab368eea4 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -100,7 +100,7 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std: return false; // skip spaces after "cppcheck-suppress" - const std::string::size_type pos2 = comment.find_first_not_of(" ", pos1+cppchecksuppress.size()); + const std::string::size_type pos2 = comment.find_first_not_of(' ', pos1+cppchecksuppress.size()); if (pos2 == std::string::npos) return false; diff --git a/lib/summaries.cpp b/lib/summaries.cpp index f0111b0a0..7ad8a0b1b 100644 --- a/lib/summaries.cpp +++ b/lib/summaries.cpp @@ -106,7 +106,7 @@ static std::vector getSummaryFiles(const std::string &filename) std::string line; while (std::getline(fin, line)) { const std::string::size_type dotA = line.find(".a"); - const std::string::size_type colon = line.find(":"); + const std::string::size_type colon = line.find(':'); if (colon > line.size() || dotA > colon) continue; std::string f = line.substr(0,colon); @@ -122,7 +122,7 @@ static std::vector getSummaryData(const std::string &line, const st const std::string::size_type start = line.find(" " + data + ":["); if (start == std::string::npos) return ret; - const std::string::size_type end = line.find("]", start); + const std::string::size_type end = line.find(']', start); if (end >= line.size()) return ret; @@ -172,7 +172,7 @@ void Summaries::loadReturn(const std::string &buildDir, std::set &s while (std::getline(fin, line)) { // Get function name const std::string::size_type pos1 = 0; - const std::string::size_type pos2 = line.find(" ", pos1); + const std::string::size_type pos2 = line.find(' ', pos1); const std::string functionName = (pos2 == std::string::npos) ? line : line.substr(0, pos2); std::vector call = getSummaryData(line, "call"); functionCalls[functionName] = call; diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 0694e1aaf..3d6dd876d 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -123,8 +123,8 @@ std::vector Suppressions::parseMultiSuppressComment(c std::vector suppressions; // If this function is called we assume that comment starts with "cppcheck-suppress[". - const std::string::size_type start_position = comment.find("["); - const std::string::size_type end_position = comment.find("]", start_position); + const std::string::size_type start_position = comment.find('['); + const std::string::size_type end_position = comment.find(']', start_position); if (end_position == std::string::npos) { if (errorMessage && errorMessage->empty()) *errorMessage = "Bad multi suppression '" + comment + "'. legal format is cppcheck-suppress[errorId, errorId symbolName=arr, ...]"; @@ -134,7 +134,7 @@ std::vector Suppressions::parseMultiSuppressComment(c // parse all suppressions for (std::string::size_type pos = start_position; pos < end_position;) { const std::string::size_type pos1 = pos + 1; - pos = comment.find(",", pos1); + pos = comment.find(',', pos1); const std::string::size_type pos2 = (pos < end_position) ? pos : end_position; if (pos1 == pos2) continue; @@ -179,7 +179,7 @@ std::string Suppressions::addSuppressionLine(const std::string &line) Suppressions::Suppression suppression; // Strip any end of line comments - std::string::size_type endpos = std::min(line.find("#"), line.find("//")); + std::string::size_type endpos = std::min(line.find('#'), line.find("//")); if (endpos != std::string::npos) { while (endpos > 0 && std::isspace(line[endpos-1])) { endpos--; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c251a51b8..574d1b169 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2051,12 +2051,12 @@ Variable::Variable(const Token *name_, const std::string &clangType, const Token setFlag(fIsRValueRef, true); } - std::string::size_type pos = clangType.find("["); + std::string::size_type pos = clangType.find('['); if (pos != std::string::npos) { setFlag(fIsArray, true); do { const std::string::size_type pos1 = pos+1; - pos = clangType.find("]", pos1); + pos = clangType.find(']', pos1); Dimension dim; dim.tok = nullptr; dim.known = pos > pos1; @@ -6613,7 +6613,7 @@ static const Token* parsedecl(const Token* type, parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings, isCpp); else if (Token::Match(type, "const|constexpr")) valuetype->constness |= (1 << (valuetype->pointer - pointer0)); - else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find("<")) { + else if (settings->clang && type->str().size() > 2 && type->str().find("::") < type->str().find('<')) { TokenList typeTokens(settings); std::string::size_type pos1 = 0; do { diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 7d7a5ae7b..be2a35c95 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1514,7 +1514,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c std::string::size_type end = 0; bool inTemplate = false; int level = 0; - while ((end = templateDeclaration.scope().find(" ", start)) != std::string::npos) { + while ((end = templateDeclaration.scope().find(' ', start)) != std::string::npos) { std::string token = templateDeclaration.scope().substr(start, end - start); // done if scopes overlap if (token == tokStart->str() && tok->strAt(-1) != "::") diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1de644ccb..2dea74e21 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1445,7 +1445,7 @@ void Tokenizer::simplifyTypedef() if (it->recordTypes.find(start->str()) != it->recordTypes.end()) { std::string::size_type spaceIdx = 0; std::string::size_type startIdx = 0; - while ((spaceIdx = removed1.find(" ", startIdx)) != std::string::npos) { + while ((spaceIdx = removed1.find(' ', startIdx)) != std::string::npos) { tok2->previous()->insertToken(removed1.substr(startIdx, spaceIdx - startIdx)); startIdx = spaceIdx + 1; } @@ -2548,7 +2548,7 @@ bool Tokenizer::simplifyUsing() tok1->deletePrevious(); break; } else { - const std::string::size_type idx = fullScope.rfind(" "); + const std::string::size_type idx = fullScope.rfind(' '); if (idx == std::string::npos) break; @@ -2695,7 +2695,7 @@ bool Tokenizer::simplifyUsing() if (tempScope->recordTypes.find(start->str()) != tempScope->recordTypes.end()) { std::string::size_type spaceIdx = 0; std::string::size_type startIdx = 0; - while ((spaceIdx = removed1.find(" ", startIdx)) != std::string::npos) { + while ((spaceIdx = removed1.find(' ', startIdx)) != std::string::npos) { tok1->previous()->insertToken(removed1.substr(startIdx, spaceIdx - startIdx)); startIdx = spaceIdx + 1; }