From 1b2bb93302116a4791cf82e9cce028dfe87ef55d Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Thu, 26 May 2016 22:52:22 +0200 Subject: Remove redundant c_str() calls. Run clang-tidy's readability-redundant-string-cstr checker. Ignore findings in kwsys. --- Source/CPack/cpack.cxx | 4 ++-- Source/CTest/cmCTestCoverageHandler.cxx | 2 +- Source/CTest/cmCTestGenericHandler.cxx | 2 +- Source/CTest/cmCTestMemCheckHandler.cxx | 22 ++++++++-------------- Source/CTest/cmCTestRunTest.cxx | 4 ++-- Source/CTest/cmCTestScriptHandler.cxx | 2 +- Source/CTest/cmParseBlanketJSCoverage.cxx | 2 +- Source/CTest/cmParseGTMCoverage.cxx | 2 +- Source/cmGeneratorExpressionEvaluationFile.cxx | 4 ++-- Source/cmGlobalUnixMakefileGenerator3.cxx | 4 ++-- Source/cmMakefileExecutableTargetGenerator.cxx | 5 ++--- Source/cmMakefileLibraryTargetGenerator.cxx | 7 +++---- Source/cmMakefileTargetGenerator.cxx | 12 +++++------- Source/cmNinjaNormalTargetGenerator.cxx | 6 +++--- Source/cmQtAutoGeneratorInitializer.cxx | 2 +- Source/cmState.cxx | 8 ++++---- Source/cmcmd.cxx | 3 +-- Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in | 2 +- Tests/CMakeLib/testGeneratedFileStream.cxx | 16 ++++++++-------- 19 files changed, 49 insertions(+), 60 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 10f60b2..94e1615 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -414,8 +414,8 @@ int main(int argc, char const* const* argv) for (generatorIt = generators.GetGeneratorsList().begin(); generatorIt != generators.GetGeneratorsList().end(); ++generatorIt) { cmDocumentationEntry e; - e.Name = generatorIt->first.c_str(); - e.Brief = generatorIt->second.c_str(); + e.Name = generatorIt->first; + e.Brief = generatorIt->second; v.push_back(e); } doc.SetSection("Generators", v); diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 51456ed..7f0bf2c 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -1622,7 +1622,7 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector& files) return false; } - prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory().c_str(); + prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory(); // DPI file should appear in build directory std::string daGlob; diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx index 1c80acd..18caabe 100644 --- a/Source/CTest/cmCTestGenericHandler.cxx +++ b/Source/CTest/cmCTestGenericHandler.cxx @@ -68,7 +68,7 @@ void cmCTestGenericHandler::Initialize() t_StringToString::iterator it; for (it = this->PersistentOptions.begin(); it != this->PersistentOptions.end(); ++it) { - this->Options[it->first] = it->second.c_str(); + this->Options[it->first] = it->second; } } diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 2cbd64d..5ae98af 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -422,7 +422,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() if (cmSystemTools::FileExists( this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str())) { this->MemoryTester = - this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str(); + this->CTest->GetCTestConfiguration("MemoryCheckCommand"); std::string testerName = cmSystemTools::GetFilenameName(this->MemoryTester); // determine the checker type @@ -438,47 +438,41 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() } } else if (cmSystemTools::FileExists( this->CTest->GetCTestConfiguration("PurifyCommand").c_str())) { - this->MemoryTester = - this->CTest->GetCTestConfiguration("PurifyCommand").c_str(); + this->MemoryTester = this->CTest->GetCTestConfiguration("PurifyCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY; } else if (cmSystemTools::FileExists( this->CTest->GetCTestConfiguration("ValgrindCommand") .c_str())) { - this->MemoryTester = - this->CTest->GetCTestConfiguration("ValgrindCommand").c_str(); + this->MemoryTester = this->CTest->GetCTestConfiguration("ValgrindCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND; } else if (cmSystemTools::FileExists( this->CTest->GetCTestConfiguration("BoundsCheckerCommand") .c_str())) { this->MemoryTester = - this->CTest->GetCTestConfiguration("BoundsCheckerCommand").c_str(); + this->CTest->GetCTestConfiguration("BoundsCheckerCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER; } if (this->CTest->GetCTestConfiguration("MemoryCheckType") == "AddressSanitizer") { - this->MemoryTester = - this->CTest->GetCTestConfiguration("CMakeCommand").c_str(); + this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::ADDRESS_SANITIZER; this->LogWithPID = true; // even if we give the log file the pid is added } if (this->CTest->GetCTestConfiguration("MemoryCheckType") == "ThreadSanitizer") { - this->MemoryTester = - this->CTest->GetCTestConfiguration("CMakeCommand").c_str(); + this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER; this->LogWithPID = true; // even if we give the log file the pid is added } if (this->CTest->GetCTestConfiguration("MemoryCheckType") == "MemorySanitizer") { - this->MemoryTester = - this->CTest->GetCTestConfiguration("CMakeCommand").c_str(); + this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::MEMORY_SANITIZER; this->LogWithPID = true; // even if we give the log file the pid is added } if (this->CTest->GetCTestConfiguration("MemoryCheckType") == "UndefinedBehaviorSanitizer") { - this->MemoryTester = - this->CTest->GetCTestConfiguration("CMakeCommand").c_str(); + this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand"); this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER; this->LogWithPID = true; // even if we give the log file the pid is added } diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index 59383af..9dda865 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -424,7 +424,7 @@ bool cmCTestRunTest::StartTest(size_t total) this->TestResult.Status = cmCTestTestHandler::BAD_COMMAND; this->TestResult.TestCount = this->TestProperties->Index; this->TestResult.Name = this->TestProperties->Name; - this->TestResult.Path = this->TestProperties->Directory.c_str(); + this->TestResult.Path = this->TestProperties->Directory; if (args.size() >= 2 && args[1] == "NOT_AVAILABLE") { this->TestProcess = new cmProcess; @@ -502,7 +502,7 @@ void cmCTestRunTest::ComputeArguments() if (this->TestHandler->MemCheck) { cmCTestMemCheckHandler* handler = static_cast(this->TestHandler); - this->ActualCommand = handler->MemoryTester.c_str(); + this->ActualCommand = handler->MemoryTester; this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable( this->TestProperties->Args[1].c_str()); } else { diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index ba0e816..6389a9d 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -485,7 +485,7 @@ int cmCTestScriptHandler::ExtractVariables() // if the dashboard root isn't specified then we can compute it from the // this->SourceDir if (this->CTestRoot.empty()) { - this->CTestRoot = cmSystemTools::GetFilenamePath(this->SourceDir).c_str(); + this->CTestRoot = cmSystemTools::GetFilenamePath(this->SourceDir); } // the script may override the minimum continuous interval diff --git a/Source/CTest/cmParseBlanketJSCoverage.cxx b/Source/CTest/cmParseBlanketJSCoverage.cxx index 1e42847..152c354 100644 --- a/Source/CTest/cmParseBlanketJSCoverage.cxx +++ b/Source/CTest/cmParseBlanketJSCoverage.cxx @@ -74,7 +74,7 @@ public: } foundFile = true; inSource = false; - filename = getValue(line, 0).c_str(); + filename = getValue(line, 0); } else if ((line.find("coverage") != line.npos) && foundFile && inSource) { /* diff --git a/Source/CTest/cmParseGTMCoverage.cxx b/Source/CTest/cmParseGTMCoverage.cxx index a065903..33ad839 100644 --- a/Source/CTest/cmParseGTMCoverage.cxx +++ b/Source/CTest/cmParseGTMCoverage.cxx @@ -121,7 +121,7 @@ bool cmParseGTMCoverage::FindFunctionInMumpsFile(std::string const& filepath, std::string line; int linenum = 0; while (cmSystemTools::GetLineFromStream(in, line)) { - std::string::size_type pos = line.find(function.c_str()); + std::string::size_type pos = line.find(function); if (pos == 0) { char nextchar = line[function.size()]; if (nextchar == ' ' || nextchar == '(' || nextchar == '\t') { diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx index c69e362..5b48eea 100644 --- a/Source/cmGeneratorExpressionEvaluationFile.cxx +++ b/Source/cmGeneratorExpressionEvaluationFile.cxx @@ -76,7 +76,7 @@ void cmGeneratorExpressionEvaluationFile::Generate( return; } - lg->GetMakefile()->AddCMakeOutputFile(outputFileName.c_str()); + lg->GetMakefile()->AddCMakeOutputFile(outputFileName); this->Files.push_back(outputFileName); outputFiles[outputFileName] = outputContent; @@ -114,7 +114,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg) if (this->InputIsContent) { inputContent = this->Input; } else { - lg->GetMakefile()->AddCMakeDependFile(this->Input.c_str()); + lg->GetMakefile()->AddCMakeDependFile(this->Input); cmSystemTools::GetPermissions(this->Input.c_str(), perm); cmsys::ifstream fin(this->Input.c_str()); if (!fin) { diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 1985461..cc5d1ba 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -958,7 +958,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule( if (emittedTargets.insert(name).second) { path = "... "; path += name; - lg->AppendEcho(commands, path.c_str()); + lg->AppendEcho(commands, path); } } } @@ -969,7 +969,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule( o != localHelp.end(); ++o) { path = "... "; path += *o; - lg->AppendEcho(commands, path.c_str()); + lg->AppendEcho(commands, path); } lg->WriteMakeRule(ruleFileStream, "Help Target", "help", no_depends, commands, true); diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 51231fc..9d42257 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -159,9 +159,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) buildEcho += linkLanguage; buildEcho += " executable "; buildEcho += targetOutPath; - this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(), - cmLocalUnixMakefileGenerator3::EchoLink, - &progress); + this->LocalGenerator->AppendEcho( + commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress); } // Build a list of compiler flags and linker flags. diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 7f5bc11..8f7dd7e 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -337,10 +337,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( buildEcho += " library "; break; } - buildEcho += targetOutPath.c_str(); - this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(), - cmLocalUnixMakefileGenerator3::EchoLink, - &progress); + buildEcho += targetOutPath; + this->LocalGenerator->AppendEcho( + commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress); } const char* forbiddenFlagVar = 0; diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 6db0553..0939698 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -311,7 +311,7 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()( std::string copyEcho = "Copying OS X content "; copyEcho += output; this->Generator->LocalGenerator->AppendEcho( - commands, copyEcho.c_str(), cmLocalUnixMakefileGenerator3::EchoBuild); + commands, copyEcho, cmLocalUnixMakefileGenerator3::EchoBuild); std::string copyCommand = "$(CMAKE_COMMAND) -E copy "; copyCommand += this->Generator->Convert(input, cmOutputConverter::NONE, cmOutputConverter::SHELL); @@ -469,7 +469,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( buildEcho += lang; buildEcho += " object "; buildEcho += relativeObj; - this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(), + this->LocalGenerator->AppendEcho(commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoBuild, &progress); } @@ -676,8 +676,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( preprocessEcho += " source to "; preprocessEcho += objI; this->LocalGenerator->AppendEcho( - commands, preprocessEcho.c_str(), - cmLocalUnixMakefileGenerator3::EchoBuild); + commands, preprocessEcho, cmLocalUnixMakefileGenerator3::EchoBuild); std::string preprocessRuleVar = "CMAKE_"; preprocessRuleVar += lang; @@ -724,8 +723,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile( assemblyEcho += " source to assembly "; assemblyEcho += objS; this->LocalGenerator->AppendEcho( - commands, assemblyEcho.c_str(), - cmLocalUnixMakefileGenerator3::EchoBuild); + commands, assemblyEcho, cmLocalUnixMakefileGenerator3::EchoBuild); std::string assemblyRuleVar = "CMAKE_"; assemblyRuleVar += lang; @@ -1073,7 +1071,7 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile( cmLocalUnixMakefileGenerator3::EchoProgress progress; this->MakeEchoProgress(progress); this->LocalGenerator->AppendEcho( - commands, comment.c_str(), cmLocalUnixMakefileGenerator3::EchoGenerate, + commands, comment, cmLocalUnixMakefileGenerator3::EchoGenerate, &progress); } } diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 90022c0..3e91545 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -445,7 +445,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() name_of_def_file += ".def "; vars["LINK_FLAGS"] += " /DEF:"; vars["LINK_FLAGS"] += this->GetLocalGenerator()->ConvertToOutputFormat( - name_of_def_file.c_str(), cmOutputConverter::SHELL); + name_of_def_file, cmOutputConverter::SHELL); } } @@ -572,13 +572,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() std::string cmd = cmakeCommand; cmd += " -E __create_def "; cmd += this->GetLocalGenerator()->ConvertToOutputFormat( - name_of_def_file.c_str(), cmOutputConverter::SHELL); + name_of_def_file, cmOutputConverter::SHELL); cmd += " "; cmNinjaDeps objs = this->GetObjects(); std::string obj_list_file = name_of_def_file; obj_list_file += ".objs"; cmd += this->GetLocalGenerator()->ConvertToOutputFormat( - obj_list_file.c_str(), cmOutputConverter::SHELL); + obj_list_file, cmOutputConverter::SHELL); preLinkCmdLines.push_back(cmd); // create a list of obj files for the -E __create_def to read cmGeneratedFileStream fout(obj_list_file.c_str()); diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 0388a95..dd19760 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -963,7 +963,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app); if (!infoFile) { std::string error = "Internal CMake error when trying to open file: "; - error += outputFile.c_str(); + error += outputFile; error += " for writing."; cmSystemTools::Error(error.c_str()); return; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index b674b4e..09b11b2 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -965,7 +965,7 @@ void cmState::Directory::SetCurrentSource(std::string const& dir) loc, this->DirectoryState->CurrentSourceDirectoryComponents); this->ComputeRelativePathTopSource(); - this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc.c_str()); + this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc); } const char* cmState::Directory::GetCurrentBinary() const @@ -984,7 +984,7 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir) loc, this->DirectoryState->CurrentBinaryDirectoryComponents); this->ComputeRelativePathTopBinary(); - this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc.c_str()); + this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc); } void cmState::Snapshot::SetListFile(const std::string& listfile) @@ -1380,8 +1380,8 @@ void cmState::Snapshot::InitializeFromParent_ForSubdirsCommand() this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory()); this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory()); - this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir.c_str()); - this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir.c_str()); + this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir); + this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir); } cmState::Directory::Directory( diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index a7718d2..471028a 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -196,8 +196,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) // If error occurs we want to continue copying next files. bool return_value = 0; for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) { - if (!cmSystemTools::CopyADirectory(args[cc].c_str(), - args[args.size() - 1].c_str())) { + if (!cmSystemTools::CopyADirectory(args[cc], args[args.size() - 1])) { std::cerr << "Error copying directory from \"" << args[cc] << "\" to \"" << args[args.size() - 1] << "\".\n"; return_value = 1; diff --git a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in index c018e08..b141942 100644 --- a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in +++ b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in @@ -51,7 +51,7 @@ main(int ac, char **av) } if (!logfile.empty()) - cmSystemTools::Touch(logfile.c_str(), true); + cmSystemTools::Touch(logfile, true); } return RETVAL; diff --git a/Tests/CMakeLib/testGeneratedFileStream.cxx b/Tests/CMakeLib/testGeneratedFileStream.cxx index 128cab4..67dd69a 100644 --- a/Tests/CMakeLib/testGeneratedFileStream.cxx +++ b/Tests/CMakeLib/testGeneratedFileStream.cxx @@ -81,14 +81,14 @@ int testGeneratedFileStream(int, char* []) cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str()); } - cmSystemTools::RemoveFile(file1.c_str()); - cmSystemTools::RemoveFile(file2.c_str()); - cmSystemTools::RemoveFile(file3.c_str()); - cmSystemTools::RemoveFile(file4.c_str()); - cmSystemTools::RemoveFile(file1tmp.c_str()); - cmSystemTools::RemoveFile(file2tmp.c_str()); - cmSystemTools::RemoveFile(file3tmp.c_str()); - cmSystemTools::RemoveFile(file4tmp.c_str()); + cmSystemTools::RemoveFile(file1); + cmSystemTools::RemoveFile(file2); + cmSystemTools::RemoveFile(file3); + cmSystemTools::RemoveFile(file4); + cmSystemTools::RemoveFile(file1tmp); + cmSystemTools::RemoveFile(file2tmp); + cmSystemTools::RemoveFile(file3tmp); + cmSystemTools::RemoveFile(file4tmp); return failed; } -- cgit v0.12