From 77a1e80380a47a2dca039ea215631e68096f30d2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 10:18:52 -0400 Subject: clang-tidy: ignore the use-trailing-return-type lint CMake isn't ready for this yet. --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index a520679..510cb9e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -13,6 +13,7 @@ modernize-*,\ -modernize-avoid-c-arrays,\ -modernize-use-nodiscard,\ -modernize-use-noexcept,\ +-modernize-use-trailing-return-type,\ -modernize-use-transparent-functors,\ performance-*,\ readability-*,\ -- cgit v0.12 From b108c9fdaf2d36c5724982549fddcf46a2dc8800 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 10:37:59 -0400 Subject: TestDriver: avoid clang-tidy lints in generated code --- Templates/TestDriver.cxx.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in index 846a828..053f1ee 100644 --- a/Templates/TestDriver.cxx.in +++ b/Templates/TestDriver.cxx.in @@ -45,7 +45,8 @@ static const int NumTests = CM_CAST(int, (note that it has to be free'd manually) */ static char* lowercase(const char* string) { - char *new_string, *p; + char *new_string; + char *p; size_t stringSize; stringSize = CM_CAST(size_t, strlen(string) + 1); @@ -63,7 +64,9 @@ static char* lowercase(const char* string) int main(int ac, char* av[]) { - int i, testNum = 0, partial_match; + int i; + int testNum = 0; + int partial_match; char *arg; int testToRun = -1; -- cgit v0.12 From 4e9e7c713e01284d48fff8f3f18b3ffb08b6eaf9 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 11:47:31 -0400 Subject: clang-tidy: ignore making members static CMake has lots of instances of this which is outside the scope of this topic right now. --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index 510cb9e..10819ef 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,6 +17,7 @@ modernize-*,\ -modernize-use-transparent-functors,\ performance-*,\ readability-*,\ +-readability-convert-member-functions-to-static,\ -readability-function-size,\ -readability-identifier-naming,\ -readability-implicit-bool-conversion,\ -- cgit v0.12 From f2a33107be2d7d701708506c4c3054799d941bd6 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 11:51:36 -0400 Subject: clang-tidy: address bugprone-branch-clone lints Arguably, many of these are bugs in `clang-tidy`. An if/else tree with other conditionals between cloned blocks may be relying on the intermediate logic to fall out of the case and inverting this logic may be non-trivial. See: https://bugs.llvm.org/show_bug.cgi?id=44165 --- Source/CPack/IFW/cmCPackIFWRepository.cxx | 4 ---- Source/CTest/cmCTestCVS.cxx | 2 ++ Source/CTest/cmCTestMemCheckHandler.cxx | 40 ++++++++++--------------------- Source/CTest/cmCTestTestHandler.cxx | 7 +++--- Source/cmCTest.cxx | 12 ++++------ Source/cmComputeLinkInformation.cxx | 1 - Source/cmDependsFortran.cxx | 4 +--- Source/cmExtraCodeLiteGenerator.cxx | 4 +--- Source/cmExtraEclipseCDT4Generator.cxx | 1 - Source/cmExtraKateGenerator.cxx | 5 ++-- Source/cmFindPackageCommand.cxx | 6 +++++ Source/cmGeneratorTarget.cxx | 8 ++++--- Source/cmInstallCommand.cxx | 1 - Source/cmLocalGenerator.cxx | 10 ++++---- Source/cmMakefile.cxx | 5 +--- Source/cmPolicies.cxx | 2 ++ Source/cmRST.cxx | 2 ++ Source/cmSeparateArgumentsCommand.cxx | 2 ++ Source/cmake.cxx | 25 +++++++------------ Source/cmcmd.cxx | 5 ++-- 20 files changed, 59 insertions(+), 87 deletions(-) diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx index a696549..f5e8744 100644 --- a/Source/CPack/IFW/cmCPackIFWRepository.cxx +++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx @@ -21,11 +21,7 @@ bool cmCPackIFWRepository::IsValid() const switch (this->Update) { case cmCPackIFWRepository::None: - valid = !this->Url.empty(); - break; case cmCPackIFWRepository::Add: - valid = !this->Url.empty(); - break; case cmCPackIFWRepository::Remove: valid = !this->Url.empty(); break; diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index 45ec390..75b534b 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -152,6 +152,8 @@ private: this->FinishRevision(); } } else if (this->Section == SectionRevisions) { + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) if (!this->Rev.Log.empty()) { // Continue the existing log. this->Rev.Log += this->Line; diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index c1ecaf1..7ad87f5 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -957,35 +957,25 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( "valgrind line " << lines[cc] << std::endl, this->Quiet); int failure = cmCTestMemCheckHandler::NO_MEMORY_FAULT; - if (vgFIM.find(lines[cc])) { + auto& line = lines[cc]; + if (vgFIM.find(line)) { failure = cmCTestMemCheckHandler::FIM; - } else if (vgFMM.find(lines[cc])) { + } else if (vgFMM.find(line)) { failure = cmCTestMemCheckHandler::FMM; - } else if (vgMLK1.find(lines[cc])) { + } else if (vgMLK1.find(line) || vgMLK2.find(line)) { failure = cmCTestMemCheckHandler::MLK; - } else if (vgMLK2.find(lines[cc])) { - failure = cmCTestMemCheckHandler::MLK; - } else if (vgPAR.find(lines[cc])) { + } else if (vgPAR.find(line)) { failure = cmCTestMemCheckHandler::PAR; - } else if (vgMPK1.find(lines[cc])) { - failure = cmCTestMemCheckHandler::MPK; - } else if (vgMPK2.find(lines[cc])) { + } else if (vgMPK1.find(line) || vgMPK2.find(line)) { failure = cmCTestMemCheckHandler::MPK; - } else if (vgUMC.find(lines[cc])) { + } else if (vgUMC.find(line)) { failure = cmCTestMemCheckHandler::UMC; - } else if (vgUMR1.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR2.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR3.find(lines[cc])) { + } else if (vgUMR1.find(line) || vgUMR2.find(line) || vgUMR3.find(line) || + vgUMR4.find(line) || vgUMR5.find(line)) { failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR4.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgUMR5.find(lines[cc])) { - failure = cmCTestMemCheckHandler::UMR; - } else if (vgIPW.find(lines[cc])) { + } else if (vgIPW.find(line)) { failure = cmCTestMemCheckHandler::IPW; - } else if (vgABR.find(lines[cc])) { + } else if (vgABR.find(line)) { failure = cmCTestMemCheckHandler::ABR; } @@ -1049,13 +1039,9 @@ bool cmCTestMemCheckHandler::ProcessMemCheckDrMemoryOutput( ostr << l << std::endl; if (drMemoryError.find(l)) { defects++; - if (unaddressableAccess.find(l)) { + if (unaddressableAccess.find(l) || uninitializedRead.find(l)) { results[cmCTestMemCheckHandler::UMR]++; - } else if (uninitializedRead.find(l)) { - results[cmCTestMemCheckHandler::UMR]++; - } else if (leak.find(l)) { - results[cmCTestMemCheckHandler::MLK]++; - } else if (handleLeak.find(l)) { + } else if (leak.find(l) || handleLeak.find(l)) { results[cmCTestMemCheckHandler::MLK]++; } else if (invalidHeapArgument.find(l)) { results[cmCTestMemCheckHandler::FMM]++; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index f9850ef..ca65946 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2402,10 +2402,9 @@ bool cmCTestTestHandler::AddTest(const std::vector& args) test.SkipReturnCode = -1; test.PreviousRuns = 0; if (this->UseIncludeRegExpFlag && - !this->IncludeTestsRegularExpression.find(testname)) { - test.IsInBasedOnREOptions = false; - } else if (this->UseExcludeRegExpFlag && !this->UseExcludeRegExpFirst && - this->ExcludeTestsRegularExpression.find(testname)) { + (!this->IncludeTestsRegularExpression.find(testname) || + (!this->UseExcludeRegExpFirst && + this->ExcludeTestsRegularExpression.find(testname)))) { test.IsInBasedOnREOptions = false; } this->TestList.push_back(test); diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index c5505f9..35a8952 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1941,13 +1941,11 @@ bool cmCTest::HandleCommandLineArguments(size_t& i, else if (this->CheckArgument(arg, "--debug"_s)) { this->Impl->Debug = true; this->Impl->ShowLineNumbers = true; - } else if (this->CheckArgument(arg, "--group"_s) && i < args.size() - 1) { - i++; - this->Impl->SpecificGroup = args[i]; - } - // This is an undocumented / deprecated option. - // "Track" has been renamed to "Group". - else if (this->CheckArgument(arg, "--track"_s) && i < args.size() - 1) { + } else if ((this->CheckArgument(arg, "--group"_s) || + // This is an undocumented / deprecated option. + // "Track" has been renamed to "Group". + this->CheckArgument(arg, "--track"_s)) && + i < args.size() - 1) { i++; this->Impl->SpecificGroup = args[i]; } else if (this->CheckArgument(arg, "--show-line-numbers"_s)) { diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 8d27699..de81f13 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1440,7 +1440,6 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item, } case cmPolicies::OLD: // OLD behavior does not warn. - break; case cmPolicies::NEW: // NEW behavior will not get here. break; diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 666306c..c45cd1c 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -29,12 +29,10 @@ static void cmFortranModuleAppendUpperLower(std::string const& mod, std::string& mod_lower) { std::string::size_type ext_len = 0; - if (cmHasLiteralSuffix(mod, ".mod")) { + if (cmHasLiteralSuffix(mod, ".mod") || cmHasLiteralSuffix(mod, ".sub")) { ext_len = 4; } else if (cmHasLiteralSuffix(mod, ".smod")) { ext_len = 5; - } else if (cmHasLiteralSuffix(mod, ".sub")) { - ext_len = 4; } std::string const& name = mod.substr(0, mod.size() - ext_len); std::string const& ext = mod.substr(mod.size() - ext_len); diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index de40c77..bf7555d 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -204,9 +204,7 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles( case cmStateEnums::STATIC_LIBRARY: { projectType = "Static Library"; } break; - case cmStateEnums::SHARED_LIBRARY: { - projectType = "Dynamic Library"; - } break; + case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: { projectType = "Dynamic Library"; } break; diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 1c5bcaa..b65f097 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -981,7 +981,6 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const } } break; case cmStateEnums::INTERFACE_LIBRARY: - break; default: break; } diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index 271bbee..de979e2 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -129,9 +129,8 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator& lg, if (targetName == "edit_cache") { const char* editCommand = localGen->GetMakefile()->GetDefinition("CMAKE_EDIT_COMMAND"); - if (editCommand == nullptr) { - insertTarget = false; - } else if (strstr(editCommand, "ccmake") != nullptr) { + if (editCommand == nullptr || + strstr(editCommand, "ccmake") != nullptr) { insertTarget = false; } } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index e996327..d1517fe 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -279,9 +279,13 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) } else if (args[i] == "MODULE") { moduleArgs.insert(i); doing = DoingNone; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (args[i] == "CONFIG") { configArgs.insert(i); doing = DoingNone; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (args[i] == "NO_MODULE") { configArgs.insert(i); doing = DoingNone; @@ -318,6 +322,8 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) this->NoSystemRegistry = true; configArgs.insert(i); doing = DoingNone; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (args[i] == "NO_CMAKE_BUILDS_PATH") { // Ignore legacy option. configArgs.insert(i); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 611f7b0..93eb8fb 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1227,7 +1227,6 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty( return result; case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: // No error. We just skip cyclic references. - return result; case cmGeneratorExpressionDAGChecker::ALREADY_SEEN: // No error. We have already seen this transitive property. return result; @@ -1295,10 +1294,9 @@ std::string AddSwiftInterfaceIncludeDirectories( dag.ReportError(nullptr, "$GetName() + ",Swift_MODULE_DIRECTORY>"); - return ""; + CM_FALLTHROUGH; case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: // No error. We just skip cyclic references. - return ""; case cmGeneratorExpressionDAGChecker::ALREADY_SEEN: // No error. We have already seen this transitive property. return ""; @@ -1689,10 +1687,14 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, std::string ext = cmSystemTools::LowerCase(sf->GetExtension()); if (sf->GetCustomCommand()) { kind = SourceKindCustomCommand; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (this->Target->GetType() == cmStateEnums::UTILITY) { kind = SourceKindExtra; } else if (this->IsSourceFilePartOfUnityBatch(sf->ResolveFullPath())) { kind = SourceKindUnityBatched; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) { kind = SourceKindHeader; } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 704db66..c9b22b6 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -661,7 +661,6 @@ bool HandleTargetsMode(std::vector const& args, // Nothing to do. An INTERFACE_LIBRARY can be installed, but the // only effect of that is to make it exportable. It installs no // other files itself. - break; default: // This should never happen due to the above type check. // Ignore the case. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f5ca5f4..e6083d3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2070,11 +2070,9 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName, case cmStateEnums::OBJECT_LIBRARY: // An object library has no single file on which to depend. // This was listed to get the target-level dependency. - return false; case cmStateEnums::INTERFACE_LIBRARY: // An interface library has no file on which to depend. // This was listed to get the target-level dependency. - return false; case cmStateEnums::UTILITY: case cmStateEnums::GLOBAL_TARGET: // A utility target has no file on which to depend. This was listed @@ -3389,11 +3387,12 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget( // Select a nice-looking reference to the source file to construct // the object file name. std::string objectName; + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) if ((relSource && !relBinary) || (subSource && !subBinary)) { objectName = relFromSource; - } else if ((relBinary && !relSource) || (subBinary && !subSource)) { - objectName = relFromBinary; - } else if (relFromBinary.length() < relFromSource.length()) { + } else if ((relBinary && !relSource) || (subBinary && !subSource) || + relFromBinary.length() < relFromSource.length()) { objectName = relFromBinary; } else { objectName = relFromSource; @@ -3552,7 +3551,6 @@ bool cmLocalGenerator::NeedBackwardsCompatibility_2_4() break; case cmPolicies::NEW: // New behavior is to ignore the variable. - return false; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: // This will never be the case because the only way to require diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 69f316d..0b532e7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2513,10 +2513,7 @@ void cmMakefile::ExpandVariablesCMP0019() for (auto l = linkLibs.begin(); l != linkLibs.end(); ++l) { std::string libName = *l; - if (libName == "optimized") { - ++l; - libName = *l; - } else if (libName == "debug") { + if (libName == "optimized" || libName == "debug") { ++l; libName = *l; } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 5c8bc98..dea3f8a 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -72,6 +72,7 @@ static const char* idToVersion(cmPolicies::PolicyID id) #define POLICY_CASE(ID, V_MAJOR, V_MINOR, V_PATCH) \ case cmPolicies::ID: \ return #V_MAJOR "." #V_MINOR "." #V_PATCH; + // NOLINTNEXTLINE(bugprone-branch-clone) CM_FOR_EACH_POLICY_ID_VERSION(POLICY_CASE) #undef POLICY_CASE case cmPolicies::CMPCOUNT: @@ -90,6 +91,7 @@ static bool isPolicyNewerThan(cmPolicies::PolicyID id, unsigned int majorV, (majorV == (V_MAJOR) && minorV + 1 < (V_MINOR) + 1) || \ (majorV == (V_MAJOR) && minorV == (V_MINOR) && \ patchV + 1 < (V_PATCH) + 1)); + // NOLINTNEXTLINE(bugprone-branch-clone) CM_FOR_EACH_POLICY_ID_VERSION(POLICY_CASE) #undef POLICY_CASE case cmPolicies::CMPCOUNT: diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx index c39d162..26e93bb 100644 --- a/Source/cmRST.cxx +++ b/Source/cmRST.cxx @@ -166,6 +166,8 @@ void cmRST::ProcessLine(std::string const& line) this->Markup = (line.find_first_not_of(" \t", 2) == std::string::npos ? MarkupEmpty : MarkupNormal); + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) if (this->CMakeDirective.find(line)) { // Output cmake domain directives and their content normally. this->NormalLine(line); diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx index 52bde7c..cfe3087 100644 --- a/Source/cmSeparateArgumentsCommand.cxx +++ b/Source/cmSeparateArgumentsCommand.cxx @@ -39,6 +39,8 @@ bool cmSeparateArgumentsCommand(std::vector const& args, if (doing == DoingVariable) { var = arg; doing = DoingMode; + // This will always clone one of the other blocks. + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (doing == DoingMode && arg == "NATIVE_COMMAND") { #ifdef _WIN32 mode = ModeWindows; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2ec893f..ea1d8ca 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -642,6 +642,8 @@ void cmake::SetArgs(const std::vector& args) path = cmSystemTools::CollapseFullPath(path); cmSystemTools::ConvertToUnixSlashes(path); this->SetHomeDirectory(path); + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (cmHasLiteralPrefix(arg, "-O")) { // There is no local generate anymore. Ignore -O option. } else if (cmHasLiteralPrefix(arg, "-B")) { @@ -681,27 +683,16 @@ void cmake::SetArgs(const std::vector& args) this->VSSolutionFile = args[++i]; } #endif - else if (cmHasLiteralPrefix(arg, "-D")) { + else if (cmHasLiteralPrefix(arg, "-D") || cmHasLiteralPrefix(arg, "-U") || + cmHasLiteralPrefix(arg, "-C")) { // skip for now - // in case '-D var=val' is given, also skip the next - // in case '-Dvar=val' is given, don't skip the next - if (arg.size() == 2) { - ++i; - } - } else if (cmHasLiteralPrefix(arg, "-U")) { - // skip for now - // in case '-U var' is given, also skip the next - // in case '-Uvar' is given, don't skip the next - if (arg.size() == 2) { - ++i; - } - } else if (cmHasLiteralPrefix(arg, "-C")) { - // skip for now - // in case '-C path' is given, also skip the next - // in case '-Cpath' is given, don't skip the next + // in case '-[DUC] argval' var' is given, also skip the next + // in case '-[DUC]argval' is given, don't skip the next if (arg.size() == 2) { ++i; } + // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165 + // NOLINTNEXTLINE(bugprone-branch-clone) } else if (cmHasLiteralPrefix(arg, "-P")) { // skip for now i++; diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index c3bd160..49d04a6 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1972,9 +1972,8 @@ bool cmVSLink::Parse(std::vector::const_iterator argBeg, // Parse the link command to extract information we need. for (; arg != argEnd; ++arg) { - if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:YES") == 0) { - this->Incremental = true; - } else if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0) { + if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:YES") == 0 || + cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0) { this->Incremental = true; } else if (cmSystemTools::Strucmp(arg->c_str(), "/MANIFEST:NO") == 0) { this->LinkGeneratesManifest = false; -- cgit v0.12 From 37872088cf52ac8a9f1adc4648e23c6fb54be097 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 13:14:40 -0400 Subject: clang-tidy: address readability-else-after-return lint --- Tests/RunCMake/exit_code.c | 3 ++- Tests/RunCMake/pseudo_cppcheck.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/RunCMake/exit_code.c b/Tests/RunCMake/exit_code.c index 3eba019..9fa8eca 100644 --- a/Tests/RunCMake/exit_code.c +++ b/Tests/RunCMake/exit_code.c @@ -21,7 +21,8 @@ int main(int argc, const char* argv[]) } if (strcmp(str, substring_success) == 0) { return EXIT_SUCCESS; - } else if (strcmp(str, substring_failure) == 0) { + } + if (strcmp(str, substring_failure) == 0) { return EXIT_FAILURE; } fprintf(stderr, "Failed to find string '%s' in '%s'\n", substring_success, diff --git a/Tests/RunCMake/pseudo_cppcheck.c b/Tests/RunCMake/pseudo_cppcheck.c index 5b1531b..e80620c 100644 --- a/Tests/RunCMake/pseudo_cppcheck.c +++ b/Tests/RunCMake/pseudo_cppcheck.c @@ -11,7 +11,8 @@ int main(int argc, char* argv[]) fprintf(stdout, "stdout from bad command line arg '-bad'\n"); fprintf(stderr, "stderr from bad command line arg '-bad'\n"); return 1; - } else if (strcmp(argv[i], "-error") == 0) { + } + if (strcmp(argv[i], "-error") == 0) { // The real cppcheck allows to set the exitcode with --error-exitcode result = 5; } -- cgit v0.12 From 80edc2cd8a22e05e8e0f690d615a06ecf25f3446 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 13:15:02 -0400 Subject: cmMakefile: use std::string_view --- Source/cmMakefile.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 0b532e7..15b8b92 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -24,6 +24,7 @@ #include "cm_jsoncpp_value.h" #include "cm_jsoncpp_writer.h" +#include "cm_static_string_view.hxx" #include "cm_sys_stat.h" #include "cmAlgorithms.h" @@ -2513,7 +2514,7 @@ void cmMakefile::ExpandVariablesCMP0019() for (auto l = linkLibs.begin(); l != linkLibs.end(); ++l) { std::string libName = *l; - if (libName == "optimized" || libName == "debug") { + if (libName == "optimized"_s || libName == "debug"_s) { ++l; libName = *l; } -- cgit v0.12 From 59b7adddc4e2c52a6783714c3844be62131ceea2 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 11:53:18 -0400 Subject: nits: replace some "c" instances with 'c' --- Source/CTest/cmCTestBuildHandler.cxx | 4 ++-- Source/CTest/cmCTestCVS.cxx | 4 ++-- Source/cmComputeLinkInformation.cxx | 4 ++-- Source/cmExtraKateGenerator.cxx | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 90c5b2a..35c2b11 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -541,11 +541,11 @@ void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml) const char* fname = launchDir.GetFile(i); if (this->IsLaunchedErrorFile(fname) && numErrorsAllowed) { numErrorsAllowed--; - fragments.insert(this->CTestLaunchDir + "/" + fname); + fragments.insert(this->CTestLaunchDir + '/' + fname); ++this->TotalErrors; } else if (this->IsLaunchedWarningFile(fname) && numWarningsAllowed) { numWarningsAllowed--; - fragments.insert(this->CTestLaunchDir + "/" + fname); + fragments.insert(this->CTestLaunchDir + '/' + fname); ++this->TotalWarnings; } } diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx index 75b534b..1209e06 100644 --- a/Source/CTest/cmCTestCVS.cxx +++ b/Source/CTest/cmCTestCVS.cxx @@ -157,7 +157,7 @@ private: if (!this->Rev.Log.empty()) { // Continue the existing log. this->Rev.Log += this->Line; - this->Rev.Log += "\n"; + this->Rev.Log += '\n'; } else if (this->Rev.Rev.empty() && this->RegexRevision.find(this->Line)) { this->Rev.Rev = this->RegexRevision.match(1); @@ -168,7 +168,7 @@ private: } else if (!this->RegexBranches.find(this->Line)) { // Start the log. this->Rev.Log += this->Line; - this->Rev.Log += "\n"; + this->Rev.Log += '\n'; } } return this->Section != SectionEnd; diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index de81f13..4d297e8 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1003,10 +1003,10 @@ std::string cmComputeLinkInformation::NoCaseExpression(const char* str) if (*s == '.') { ret += *s; } else { - ret += "["; + ret += '['; ret += static_cast(tolower(*s)); ret += static_cast(toupper(*s)); - ret += "]"; + ret += ']'; } s++; } diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx index de979e2..01fac5a 100644 --- a/Source/cmExtraKateGenerator.cxx +++ b/Source/cmExtraKateGenerator.cxx @@ -273,7 +273,7 @@ std::string cmExtraKateGenerator::GenerateProjectName( const std::string& name, const std::string& type, const std::string& path) const { - return name + (type.empty() ? "" : "-") + type + "@" + path; + return name + (type.empty() ? "" : "-") + type + '@' + path; } std::string cmExtraKateGenerator::GetPathBasename( -- cgit v0.12 From 89207abf1f32b862ba509b94967c57d9120d9c13 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 11:54:56 -0400 Subject: cmParseCacheCoverage: use cmSystemTools::SplitString --- Source/CTest/cmParseCacheCoverage.cxx | 30 ++++-------------------------- Source/CTest/cmParseCacheCoverage.h | 3 --- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx index 1a5e7c5..84d7de0 100644 --- a/Source/CTest/cmParseCacheCoverage.cxx +++ b/Source/CTest/cmParseCacheCoverage.cxx @@ -4,6 +4,7 @@ #include #include #include +#include #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" @@ -69,26 +70,6 @@ void cmParseCacheCoverage::RemoveUnCoveredFiles() } } -bool cmParseCacheCoverage::SplitString(std::vector& args, - std::string const& line) -{ - std::string::size_type pos1 = 0; - std::string::size_type pos2 = line.find(',', 0); - if (pos2 == std::string::npos) { - return false; - } - std::string arg; - while (pos2 != std::string::npos) { - arg = line.substr(pos1, pos2 - pos1); - args.push_back(arg); - pos1 = pos2 + 1; - pos2 = line.find(',', pos1); - } - arg = line.substr(pos1); - args.push_back(arg); - return true; -} - bool cmParseCacheCoverage::ReadCMCovFile(const char* file) { cmsys::ifstream in(file); @@ -97,7 +78,6 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file) return false; } std::string line; - std::vector separateLine; if (!cmSystemTools::GetLineFromStream(in, line)) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Empty file : " << file @@ -106,8 +86,8 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file) << line << "]\n"); return false; } - separateLine.clear(); - this->SplitString(separateLine, line); + std::vector separateLine = + cmSystemTools::SplitString(line, ','); if (separateLine.size() != 4 || separateLine[0] != "Routine" || separateLine[1] != "Line" || separateLine[2] != "RtnLine" || separateLine[3] != "Code") { @@ -120,10 +100,8 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file) std::string routine; std::string filepath; while (cmSystemTools::GetLineFromStream(in, line)) { - // clear out line argument vector - separateLine.clear(); // parse the comma separated line - this->SplitString(separateLine, line); + separateLine = cmSystemTools::SplitString(line, ','); // might have more because code could have a quoted , in it // but we only care about the first 3 args anyway if (separateLine.size() < 4) { diff --git a/Source/CTest/cmParseCacheCoverage.h b/Source/CTest/cmParseCacheCoverage.h index 3b554f3..a8200b7 100644 --- a/Source/CTest/cmParseCacheCoverage.h +++ b/Source/CTest/cmParseCacheCoverage.h @@ -6,7 +6,6 @@ #include "cmConfigure.h" // IWYU pragma: keep #include -#include #include "cmParseMumpsCoverage.h" @@ -31,8 +30,6 @@ protected: void RemoveUnCoveredFiles(); // Read a single mcov file bool ReadCMCovFile(const char* f); - // split a string based on , - bool SplitString(std::vector& args, std::string const& line); }; #endif -- cgit v0.12 From 609c3b7cdc4f633a49424de667ba332e483ffb46 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 11:55:38 -0400 Subject: cmComputeLinkInformation: reserve space in built-up string This should avoid any reallocations that would occur in this function. --- Source/cmComputeLinkInformation.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 4d297e8..d8a6204 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -998,6 +998,7 @@ std::string cmComputeLinkInformation::CreateExtensionRegex( std::string cmComputeLinkInformation::NoCaseExpression(const char* str) { std::string ret; + ret.reserve(strlen(str) * 4); const char* s = str; while (*s) { if (*s == '.') { -- cgit v0.12 From f413727d27be474dc2b943b434ea12c357f65473 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 11:56:47 -0400 Subject: clang-tidy: address bugprone-sizeof-expression lint --- Source/cmGlobalGenerator.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ccbbf53..4a6f6fb 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2253,10 +2253,12 @@ std::string cmGlobalGenerator::IndexGeneratorTargetUniquely( // Use a ":" prefix to avoid conflict with project-defined targets. // We must satisfy cmGeneratorExpression::IsValidTargetName so use no // other special characters. - char buf[1 + sizeof(gt) * 2]; + constexpr size_t sizeof_ptr = + sizeof(gt); // NOLINT(bugprone-sizeof-expression) + char buf[1 + sizeof_ptr * 2]; char* b = buf; *b++ = ':'; - for (size_t i = 0; i < sizeof(gt); ++i) { + for (size_t i = 0; i < sizeof_ptr; ++i) { unsigned char const c = reinterpret_cast(>)[i]; *b++ = hexDigits[(c & 0xf0) >> 4]; *b++ = hexDigits[(c & 0x0f)]; -- cgit v0.12 From 7cb72fadc8f78945fce75d23f9a4cd6ce0e92e72 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 8 Apr 2020 13:10:45 -0400 Subject: cmConfigureFileCommand: simplify no-op argument handling --- Source/cmConfigureFileCommand.cxx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx index 8767386..bac9337 100644 --- a/Source/cmConfigureFileCommand.cxx +++ b/Source/cmConfigureFileCommand.cxx @@ -2,6 +2,12 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmConfigureFileCommand.h" +#include + +#include + +#include "cm_static_string_view.hxx" + #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -56,6 +62,18 @@ bool cmConfigureFileCommand(std::vector const& args, bool copyOnly = false; bool escapeQuotes = false; + static std::set noopOptions = { + /* Legacy. */ + "IMMEDIATE"_s, + /* Handled by NewLineStyle member. */ + "NEWLINE_STYLE"_s, + "LF"_s, + "UNIX"_s, + "CRLF"_s, + "WIN32"_s, + "DOS"_s, + }; + std::string unknown_args; bool atOnly = false; for (unsigned int i = 2; i < args.size(); ++i) { @@ -70,12 +88,8 @@ bool cmConfigureFileCommand(std::vector const& args, escapeQuotes = true; } else if (args[i] == "@ONLY") { atOnly = true; - } else if (args[i] == "IMMEDIATE") { - /* Ignore legacy option. */ - } else if (args[i] == "NEWLINE_STYLE" || args[i] == "LF" || - args[i] == "UNIX" || args[i] == "CRLF" || args[i] == "WIN32" || - args[i] == "DOS") { - /* Options handled by NewLineStyle member above. */ + } else if (noopOptions.find(args[i]) != noopOptions.end()) { + /* Ignore no-op options. */ } else { unknown_args += " "; unknown_args += args[i]; -- cgit v0.12