Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 0 additions & 1 deletion clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ These do not (always) increase readability.

To be documented.

`performance-faster-string-find`<br>
`bugprone-narrowing-conversions`<br>
`performance-no-automatic-move`<br>

Expand Down
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string>
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;
Expand Down
2 changes: 1 addition & 1 deletion gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 23 additions & 23 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ static std::string unquote(const std::string &s)
static std::vector<std::string> splitString(const std::string &line)
{
std::vector<std::string> 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])))
Expand All @@ -159,21 +159,21 @@ static std::vector<std::string> 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("::");
pos1 = pos2 + 2;
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] == '<')
Expand All @@ -186,7 +186,7 @@ static std::vector<std::string> splitString(const std::string &line)
}
if (level > 1 && pos2 + 1 >= line.size())
return std::vector<std::string> {};
pos2 = line.find(" ", pos2);
pos2 = line.find(' ', pos2);
if (pos2 != std::string::npos)
--pos2;
}
Expand All @@ -196,7 +196,7 @@ static std::vector<std::string> 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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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<Token *> lpar;
for (const std::string &s: splitString(type)) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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, "[");
Expand Down Expand Up @@ -1577,15 +1577,15 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f)
std::string line;
std::vector<AstNodePtr> 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) == "-<<<NULL>>>") {
const int level = (pos1 - 1) / 2;
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);
Expand Down
20 changes: 10 additions & 10 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ 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")) {
scriptFile = getFullPath(fileName, exename);
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);
Expand All @@ -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;
}
Expand All @@ -215,7 +215,7 @@ static std::vector<std::string> 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;
Expand Down Expand Up @@ -415,16 +415,16 @@ static bool reportClangErrors(std::istream &is, const std::function<void(const E
continue;

// file:line:column: error: ....
const std::string::size_type pos2 = line.rfind(":", pos3 - 1);
const std::string::size_type pos1 = line.rfind(":", pos2 - 1);
const std::string::size_type pos2 = line.rfind(':', pos3 - 1);
const std::string::size_type pos1 = line.rfind(':', pos2 - 1);

if (pos1 >= pos2 || pos2 >= pos3)
continue;

const std::string filename = line.substr(0, pos1);
const std::string linenr = line.substr(pos1+1, pos2-pos1-1);
const std::string colnr = line.substr(pos2+1, pos3-pos2-1);
const std::string msg = line.substr(line.find(":", pos3+1) + 2);
const std::string msg = line.substr(line.find(':', pos3+1) + 2);

const std::string locFile = Path::toNativeSeparators(filename);
ErrorMessage::FileLocation loc;
Expand Down Expand Up @@ -1701,8 +1701,8 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
endColumnPos = line.find(": warning:");
}

const std::size_t endLinePos = line.rfind(":", endColumnPos-1);
const std::size_t endNamePos = line.rfind(":", endLinePos - 1);
const std::size_t endLinePos = line.rfind(':', endColumnPos-1);
const std::size_t endNamePos = line.rfind(':', endLinePos - 1);
const std::size_t endMsgTypePos = line.find(':', endColumnPos + 2);
const std::size_t endErrorPos = line.rfind('[', std::string::npos);
if (endLinePos==std::string::npos || endNamePos==std::string::npos || endMsgTypePos==std::string::npos || endErrorPos==std::string::npos)
Expand Down
6 changes: 3 additions & 3 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenLis
const Token *tok = e.first;
std::string info = e.second;

if (info.compare(0,8,"$symbol:") == 0 && info.find("\n") < info.size()) {
const std::string::size_type pos = info.find("\n");
if (info.compare(0,8,"$symbol:") == 0 && info.find('\n') < info.size()) {
const std::string::size_type pos = info.find('\n');
const std::string &symbolName = info.substr(8, pos - 8);
info = replaceStr(info.substr(pos+1), "$symbol", symbolName);
}
Expand Down Expand Up @@ -361,7 +361,7 @@ void ErrorMessage::deserialize(const std::string &data)
break;
}
const std::string::size_type start = pos;
pos = temp.find("\t", pos);
pos = temp.find('\t', pos);
if (pos == std::string::npos) {
substrings.push_back(temp.substr(start));
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/fwdanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
// TODO: This is a quick bailout to avoid FP #9420, there are false negatives (TODO_ASSERT_EQUALS)
return Result(Result::Type::BAILOUT);

if (expr->isName() && 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()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ bool ImportProject::importCompileCommands(std::istream &istr)
for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) {
if (arg.is<std::string>()) {
std::string str = arg.get<std::string>();
if (str.find(" ") != std::string::npos)
if (str.find(' ') != std::string::npos)
str = "\"" + str + "\"";
command += str + " ";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions lib/summaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static std::vector<std::string> 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);
Expand All @@ -122,7 +122,7 @@ static std::vector<std::string> 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;

Expand Down Expand Up @@ -172,7 +172,7 @@ void Summaries::loadReturn(const std::string &buildDir, std::set<std::string> &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<std::string> call = getSummaryData(line, "call");
functionCalls[functionName] = call;
Expand Down
Loading