From 96704c997143dfd126db9c61d2e9cc129fabe2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 5 Jan 2021 17:51:32 +0100 Subject: [PATCH] fixed and enabled some more clang-tidy warnings (#3007) --- .clang-tidy | 2 +- cli/cppcheckexecutor.cpp | 2 +- lib/checkother.cpp | 2 +- lib/clangimport.cpp | 2 +- lib/exprengine.cpp | 6 +++--- lib/timer.cpp | 2 +- lib/valueflow.cpp | 7 ++++--- test/testsuite.cpp | 2 +- test/testuninitvar.cpp | 2 +- tools/dmake.cpp | 4 ++-- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index be09c19a5..5a7fb872e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-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,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move' +Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-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,-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-non-const-parameter,-misc-non-private-member-variables-in-classes,-bugprone-suspicious-string-compare,-readability-misleading-indentation,-misc-unused-parameters-,-clang-analyzer-*,-bugprone-signed-char-misuse,-readability-make-member-function-const,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-bugprone-suspicious-include,-modernize-replace-random-shuffle' CheckOptions: - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic value: '1' \ No newline at end of file diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 14b3cdeb7..711d7b52d 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -357,7 +357,7 @@ static bool IsAddressOnStack(const void* ptr) */ #define DECLARE_SIGNAL(x) std::make_pair(x, #x) -typedef std::map Signalmap_t; +using Signalmap_t = std::map; static const Signalmap_t listofsignals = { DECLARE_SIGNAL(SIGABRT), DECLARE_SIGNAL(SIGBUS), diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 792bf019e..a01d491eb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2022,7 +2022,7 @@ namespace { for (const Scope &scope : symbolDatabase->scopeList) { // only add const functions that do not have a non-const overloaded version // since it is pretty much impossible to tell which is being called. - typedef std::map > StringFunctionMap; + using StringFunctionMap = std::map >; StringFunctionMap functionsByName; for (const Function &func : scope.functionList) { functionsByName[func.tokenDef->str()].push_back(&func); diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index f1238eafe..9c1c26391 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -296,7 +296,7 @@ namespace clangimport { }; class AstNode; - typedef std::shared_ptr AstNodePtr; + using AstNodePtr = std::shared_ptr; class AstNode { public: diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index ef0953216..adf1746a1 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -394,7 +394,7 @@ namespace { } } - typedef std::map Memory; + using Memory = std::map; Memory memory; int * const symbolValueIndex; ErrorLogger *errorLogger; @@ -1108,8 +1108,8 @@ std::string ExprEngine::IntegerTruncation::getSymbolicExpression() const class ExprData { public: - typedef std::map ValueExpr; - typedef std::vector AssertionList; + using ValueExpr = std::map; + using AssertionList = std::vector; class BailoutValueException: public ExprEngineException { public: diff --git a/lib/timer.cpp b/lib/timer.cpp index 6613ad228..6fcdfc29d 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -32,7 +32,7 @@ */ namespace { - typedef std::pair dataElementType; + using dataElementType = std::pair; bool more_second_sec(const dataElementType& lhs, const dataElementType& rhs) { return lhs.second.seconds() > rhs.second.seconds(); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 02f88b4a4..c4a2c4a6d 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1334,7 +1334,7 @@ static void valueFlowSameExpressions(TokenList *tokenlist) static void valueFlowTerminatingCondition(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings) { const bool cpp = symboldatabase->isCPP(); - typedef std::pair Condition; + using Condition = std::pair; for (const Scope * scope : symboldatabase->functionScopes) { bool skipFunction = false; std::vector conds; @@ -2430,8 +2430,9 @@ static Analyzer::Action valueFlowForwardVariable(Token* const startToken, TokenList* const tokenlist, const Settings* const settings) { + auto aliases = getAliasesFromValues(values); return valueFlowForwardVariable( - startToken, endToken, var, std::move(values), getAliasesFromValues(values), tokenlist, settings); + startToken, endToken, var, std::move(values), std::move(aliases), tokenlist, settings); } // Old deprecated version @@ -2777,7 +2778,7 @@ std::vector getLifetimeTokens(const Token* tok, bool escape, Valu for (const Token* returnTok : returns) { if (returnTok == tok) continue; - for (LifetimeToken& lt : getLifetimeTokens(returnTok, escape, std::move(errorPath), depth - 1)) { + for (LifetimeToken& lt : getLifetimeTokens(returnTok, escape, errorPath, depth - 1)) { const Token* argvarTok = lt.token; const Variable* argvar = argvarTok->variable(); if (!argvar) diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 51a1a64e8..80dc4ca04 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -38,7 +38,7 @@ struct CompareFixtures { } }; -typedef std::set TestSet; +using TestSet = std::set; class TestRegistry { TestSet _tests; public: diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 36f24fc74..77dbb8768 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -326,7 +326,7 @@ private: checkUninitVar("int f() {\n" " int a,b,c;\n" " a = b = c;\n" - "}", "test.cpp", /*verify=*/ false); + "}", "test.cpp", /*debugwarnings=*/ false); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: c\n", errout.str()); checkUninitVar("static void foo()\n" diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 5fbe230e6..fbb2fc7f5 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -494,8 +494,8 @@ int main(int argc, char **argv) fout << "\txmllint --noout --relaxng cppcheck-errors.rng /tmp/example.xml\n"; fout << "\ncheckCWEEntries: /tmp/errorlist.xml\n"; fout << "\t./tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n"; - fout << ".PHONY: validateRules\n", - fout << "validateRules:\n"; + fout << ".PHONY: validateRules\n"; + fout << "validateRules:\n"; fout << "\txmllint --noout rules/*.xml\n"; fout << "\n###### Build\n\n";