Remove redundant c_str() calls.

Run clang-tidy's readability-redundant-string-cstr checker.
Ignore findings in kwsys.
This commit is contained in:
Daniel Pfeifer 2016-05-26 22:52:22 +02:00
parent acd8a73044
commit 1b2bb93302
19 changed files with 49 additions and 60 deletions

View File

@ -414,8 +414,8 @@ int main(int argc, char const* const* argv)
for (generatorIt = generators.GetGeneratorsList().begin(); for (generatorIt = generators.GetGeneratorsList().begin();
generatorIt != generators.GetGeneratorsList().end(); ++generatorIt) { generatorIt != generators.GetGeneratorsList().end(); ++generatorIt) {
cmDocumentationEntry e; cmDocumentationEntry e;
e.Name = generatorIt->first.c_str(); e.Name = generatorIt->first;
e.Brief = generatorIt->second.c_str(); e.Brief = generatorIt->second;
v.push_back(e); v.push_back(e);
} }
doc.SetSection("Generators", v); doc.SetSection("Generators", v);

View File

@ -1622,7 +1622,7 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
return false; return false;
} }
prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory().c_str(); prevBinaryDir = cmSystemTools::GetCurrentWorkingDirectory();
// DPI file should appear in build directory // DPI file should appear in build directory
std::string daGlob; std::string daGlob;

View File

@ -68,7 +68,7 @@ void cmCTestGenericHandler::Initialize()
t_StringToString::iterator it; t_StringToString::iterator it;
for (it = this->PersistentOptions.begin(); for (it = this->PersistentOptions.begin();
it != this->PersistentOptions.end(); ++it) { it != this->PersistentOptions.end(); ++it) {
this->Options[it->first] = it->second.c_str(); this->Options[it->first] = it->second;
} }
} }

View File

@ -422,7 +422,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
if (cmSystemTools::FileExists( if (cmSystemTools::FileExists(
this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str())) { this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str())) {
this->MemoryTester = this->MemoryTester =
this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str(); this->CTest->GetCTestConfiguration("MemoryCheckCommand");
std::string testerName = std::string testerName =
cmSystemTools::GetFilenameName(this->MemoryTester); cmSystemTools::GetFilenameName(this->MemoryTester);
// determine the checker type // determine the checker type
@ -438,47 +438,41 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
} }
} else if (cmSystemTools::FileExists( } else if (cmSystemTools::FileExists(
this->CTest->GetCTestConfiguration("PurifyCommand").c_str())) { this->CTest->GetCTestConfiguration("PurifyCommand").c_str())) {
this->MemoryTester = this->MemoryTester = this->CTest->GetCTestConfiguration("PurifyCommand");
this->CTest->GetCTestConfiguration("PurifyCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY; this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
} else if (cmSystemTools::FileExists( } else if (cmSystemTools::FileExists(
this->CTest->GetCTestConfiguration("ValgrindCommand") this->CTest->GetCTestConfiguration("ValgrindCommand")
.c_str())) { .c_str())) {
this->MemoryTester = this->MemoryTester = this->CTest->GetCTestConfiguration("ValgrindCommand");
this->CTest->GetCTestConfiguration("ValgrindCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND; this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
} else if (cmSystemTools::FileExists( } else if (cmSystemTools::FileExists(
this->CTest->GetCTestConfiguration("BoundsCheckerCommand") this->CTest->GetCTestConfiguration("BoundsCheckerCommand")
.c_str())) { .c_str())) {
this->MemoryTester = this->MemoryTester =
this->CTest->GetCTestConfiguration("BoundsCheckerCommand").c_str(); this->CTest->GetCTestConfiguration("BoundsCheckerCommand");
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER; this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
} }
if (this->CTest->GetCTestConfiguration("MemoryCheckType") == if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
"AddressSanitizer") { "AddressSanitizer") {
this->MemoryTester = this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::ADDRESS_SANITIZER; this->MemoryTesterStyle = cmCTestMemCheckHandler::ADDRESS_SANITIZER;
this->LogWithPID = true; // even if we give the log file the pid is added this->LogWithPID = true; // even if we give the log file the pid is added
} }
if (this->CTest->GetCTestConfiguration("MemoryCheckType") == if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
"ThreadSanitizer") { "ThreadSanitizer") {
this->MemoryTester = this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER; this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER;
this->LogWithPID = true; // even if we give the log file the pid is added this->LogWithPID = true; // even if we give the log file the pid is added
} }
if (this->CTest->GetCTestConfiguration("MemoryCheckType") == if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
"MemorySanitizer") { "MemorySanitizer") {
this->MemoryTester = this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::MEMORY_SANITIZER; this->MemoryTesterStyle = cmCTestMemCheckHandler::MEMORY_SANITIZER;
this->LogWithPID = true; // even if we give the log file the pid is added this->LogWithPID = true; // even if we give the log file the pid is added
} }
if (this->CTest->GetCTestConfiguration("MemoryCheckType") == if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
"UndefinedBehaviorSanitizer") { "UndefinedBehaviorSanitizer") {
this->MemoryTester = this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER; this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER;
this->LogWithPID = true; // even if we give the log file the pid is added this->LogWithPID = true; // even if we give the log file the pid is added
} }

View File

@ -424,7 +424,7 @@ bool cmCTestRunTest::StartTest(size_t total)
this->TestResult.Status = cmCTestTestHandler::BAD_COMMAND; this->TestResult.Status = cmCTestTestHandler::BAD_COMMAND;
this->TestResult.TestCount = this->TestProperties->Index; this->TestResult.TestCount = this->TestProperties->Index;
this->TestResult.Name = this->TestProperties->Name; 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") { if (args.size() >= 2 && args[1] == "NOT_AVAILABLE") {
this->TestProcess = new cmProcess; this->TestProcess = new cmProcess;
@ -502,7 +502,7 @@ void cmCTestRunTest::ComputeArguments()
if (this->TestHandler->MemCheck) { if (this->TestHandler->MemCheck) {
cmCTestMemCheckHandler* handler = cmCTestMemCheckHandler* handler =
static_cast<cmCTestMemCheckHandler*>(this->TestHandler); static_cast<cmCTestMemCheckHandler*>(this->TestHandler);
this->ActualCommand = handler->MemoryTester.c_str(); this->ActualCommand = handler->MemoryTester;
this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable( this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable(
this->TestProperties->Args[1].c_str()); this->TestProperties->Args[1].c_str());
} else { } else {

View File

@ -485,7 +485,7 @@ int cmCTestScriptHandler::ExtractVariables()
// if the dashboard root isn't specified then we can compute it from the // if the dashboard root isn't specified then we can compute it from the
// this->SourceDir // this->SourceDir
if (this->CTestRoot.empty()) { 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 // the script may override the minimum continuous interval

View File

@ -74,7 +74,7 @@ public:
} }
foundFile = true; foundFile = true;
inSource = false; inSource = false;
filename = getValue(line, 0).c_str(); filename = getValue(line, 0);
} else if ((line.find("coverage") != line.npos) && foundFile && } else if ((line.find("coverage") != line.npos) && foundFile &&
inSource) { inSource) {
/* /*

View File

@ -121,7 +121,7 @@ bool cmParseGTMCoverage::FindFunctionInMumpsFile(std::string const& filepath,
std::string line; std::string line;
int linenum = 0; int linenum = 0;
while (cmSystemTools::GetLineFromStream(in, line)) { 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) { if (pos == 0) {
char nextchar = line[function.size()]; char nextchar = line[function.size()];
if (nextchar == ' ' || nextchar == '(' || nextchar == '\t') { if (nextchar == ' ' || nextchar == '(' || nextchar == '\t') {

View File

@ -76,7 +76,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(
return; return;
} }
lg->GetMakefile()->AddCMakeOutputFile(outputFileName.c_str()); lg->GetMakefile()->AddCMakeOutputFile(outputFileName);
this->Files.push_back(outputFileName); this->Files.push_back(outputFileName);
outputFiles[outputFileName] = outputContent; outputFiles[outputFileName] = outputContent;
@ -114,7 +114,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg)
if (this->InputIsContent) { if (this->InputIsContent) {
inputContent = this->Input; inputContent = this->Input;
} else { } else {
lg->GetMakefile()->AddCMakeDependFile(this->Input.c_str()); lg->GetMakefile()->AddCMakeDependFile(this->Input);
cmSystemTools::GetPermissions(this->Input.c_str(), perm); cmSystemTools::GetPermissions(this->Input.c_str(), perm);
cmsys::ifstream fin(this->Input.c_str()); cmsys::ifstream fin(this->Input.c_str());
if (!fin) { if (!fin) {

View File

@ -958,7 +958,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
if (emittedTargets.insert(name).second) { if (emittedTargets.insert(name).second) {
path = "... "; path = "... ";
path += name; path += name;
lg->AppendEcho(commands, path.c_str()); lg->AppendEcho(commands, path);
} }
} }
} }
@ -969,7 +969,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
o != localHelp.end(); ++o) { o != localHelp.end(); ++o) {
path = "... "; path = "... ";
path += *o; path += *o;
lg->AppendEcho(commands, path.c_str()); lg->AppendEcho(commands, path);
} }
lg->WriteMakeRule(ruleFileStream, "Help Target", "help", no_depends, lg->WriteMakeRule(ruleFileStream, "Help Target", "help", no_depends,
commands, true); commands, true);

View File

@ -159,9 +159,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
buildEcho += linkLanguage; buildEcho += linkLanguage;
buildEcho += " executable "; buildEcho += " executable ";
buildEcho += targetOutPath; buildEcho += targetOutPath;
this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(), this->LocalGenerator->AppendEcho(
cmLocalUnixMakefileGenerator3::EchoLink, commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress);
&progress);
} }
// Build a list of compiler flags and linker flags. // Build a list of compiler flags and linker flags.

View File

@ -337,10 +337,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
buildEcho += " library "; buildEcho += " library ";
break; break;
} }
buildEcho += targetOutPath.c_str(); buildEcho += targetOutPath;
this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(), this->LocalGenerator->AppendEcho(
cmLocalUnixMakefileGenerator3::EchoLink, commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress);
&progress);
} }
const char* forbiddenFlagVar = 0; const char* forbiddenFlagVar = 0;

View File

@ -311,7 +311,7 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
std::string copyEcho = "Copying OS X content "; std::string copyEcho = "Copying OS X content ";
copyEcho += output; copyEcho += output;
this->Generator->LocalGenerator->AppendEcho( this->Generator->LocalGenerator->AppendEcho(
commands, copyEcho.c_str(), cmLocalUnixMakefileGenerator3::EchoBuild); commands, copyEcho, cmLocalUnixMakefileGenerator3::EchoBuild);
std::string copyCommand = "$(CMAKE_COMMAND) -E copy "; std::string copyCommand = "$(CMAKE_COMMAND) -E copy ";
copyCommand += this->Generator->Convert(input, cmOutputConverter::NONE, copyCommand += this->Generator->Convert(input, cmOutputConverter::NONE,
cmOutputConverter::SHELL); cmOutputConverter::SHELL);
@ -469,7 +469,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
buildEcho += lang; buildEcho += lang;
buildEcho += " object "; buildEcho += " object ";
buildEcho += relativeObj; buildEcho += relativeObj;
this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(), this->LocalGenerator->AppendEcho(commands, buildEcho,
cmLocalUnixMakefileGenerator3::EchoBuild, cmLocalUnixMakefileGenerator3::EchoBuild,
&progress); &progress);
} }
@ -676,8 +676,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
preprocessEcho += " source to "; preprocessEcho += " source to ";
preprocessEcho += objI; preprocessEcho += objI;
this->LocalGenerator->AppendEcho( this->LocalGenerator->AppendEcho(
commands, preprocessEcho.c_str(), commands, preprocessEcho, cmLocalUnixMakefileGenerator3::EchoBuild);
cmLocalUnixMakefileGenerator3::EchoBuild);
std::string preprocessRuleVar = "CMAKE_"; std::string preprocessRuleVar = "CMAKE_";
preprocessRuleVar += lang; preprocessRuleVar += lang;
@ -724,8 +723,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
assemblyEcho += " source to assembly "; assemblyEcho += " source to assembly ";
assemblyEcho += objS; assemblyEcho += objS;
this->LocalGenerator->AppendEcho( this->LocalGenerator->AppendEcho(
commands, assemblyEcho.c_str(), commands, assemblyEcho, cmLocalUnixMakefileGenerator3::EchoBuild);
cmLocalUnixMakefileGenerator3::EchoBuild);
std::string assemblyRuleVar = "CMAKE_"; std::string assemblyRuleVar = "CMAKE_";
assemblyRuleVar += lang; assemblyRuleVar += lang;
@ -1073,7 +1071,7 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile(
cmLocalUnixMakefileGenerator3::EchoProgress progress; cmLocalUnixMakefileGenerator3::EchoProgress progress;
this->MakeEchoProgress(progress); this->MakeEchoProgress(progress);
this->LocalGenerator->AppendEcho( this->LocalGenerator->AppendEcho(
commands, comment.c_str(), cmLocalUnixMakefileGenerator3::EchoGenerate, commands, comment, cmLocalUnixMakefileGenerator3::EchoGenerate,
&progress); &progress);
} }
} }

View File

@ -445,7 +445,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
name_of_def_file += ".def "; name_of_def_file += ".def ";
vars["LINK_FLAGS"] += " /DEF:"; vars["LINK_FLAGS"] += " /DEF:";
vars["LINK_FLAGS"] += this->GetLocalGenerator()->ConvertToOutputFormat( 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; std::string cmd = cmakeCommand;
cmd += " -E __create_def "; cmd += " -E __create_def ";
cmd += this->GetLocalGenerator()->ConvertToOutputFormat( cmd += this->GetLocalGenerator()->ConvertToOutputFormat(
name_of_def_file.c_str(), cmOutputConverter::SHELL); name_of_def_file, cmOutputConverter::SHELL);
cmd += " "; cmd += " ";
cmNinjaDeps objs = this->GetObjects(); cmNinjaDeps objs = this->GetObjects();
std::string obj_list_file = name_of_def_file; std::string obj_list_file = name_of_def_file;
obj_list_file += ".objs"; obj_list_file += ".objs";
cmd += this->GetLocalGenerator()->ConvertToOutputFormat( cmd += this->GetLocalGenerator()->ConvertToOutputFormat(
obj_list_file.c_str(), cmOutputConverter::SHELL); obj_list_file, cmOutputConverter::SHELL);
preLinkCmdLines.push_back(cmd); preLinkCmdLines.push_back(cmd);
// create a list of obj files for the -E __create_def to read // create a list of obj files for the -E __create_def to read
cmGeneratedFileStream fout(obj_list_file.c_str()); cmGeneratedFileStream fout(obj_list_file.c_str());

View File

@ -963,7 +963,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(
cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app); cmsys::ofstream infoFile(outputFile.c_str(), std::ios::app);
if (!infoFile) { if (!infoFile) {
std::string error = "Internal CMake error when trying to open file: "; std::string error = "Internal CMake error when trying to open file: ";
error += outputFile.c_str(); error += outputFile;
error += " for writing."; error += " for writing.";
cmSystemTools::Error(error.c_str()); cmSystemTools::Error(error.c_str());
return; return;

View File

@ -965,7 +965,7 @@ void cmState::Directory::SetCurrentSource(std::string const& dir)
loc, this->DirectoryState->CurrentSourceDirectoryComponents); loc, this->DirectoryState->CurrentSourceDirectoryComponents);
this->ComputeRelativePathTopSource(); 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 const char* cmState::Directory::GetCurrentBinary() const
@ -984,7 +984,7 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir)
loc, this->DirectoryState->CurrentBinaryDirectoryComponents); loc, this->DirectoryState->CurrentBinaryDirectoryComponents);
this->ComputeRelativePathTopBinary(); 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) 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_SOURCE_DIR", this->State->GetSourceDirectory());
this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory()); this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir.c_str()); this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir);
this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir.c_str()); this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir);
} }
cmState::Directory::Directory( cmState::Directory::Directory(

View File

@ -196,8 +196,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// If error occurs we want to continue copying next files. // If error occurs we want to continue copying next files.
bool return_value = 0; bool return_value = 0;
for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) { for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
if (!cmSystemTools::CopyADirectory(args[cc].c_str(), if (!cmSystemTools::CopyADirectory(args[cc], args[args.size() - 1])) {
args[args.size() - 1].c_str())) {
std::cerr << "Error copying directory from \"" << args[cc] std::cerr << "Error copying directory from \"" << args[cc]
<< "\" to \"" << args[args.size() - 1] << "\".\n"; << "\" to \"" << args[args.size() - 1] << "\".\n";
return_value = 1; return_value = 1;

View File

@ -51,7 +51,7 @@ main(int ac, char **av)
} }
if (!logfile.empty()) if (!logfile.empty())
cmSystemTools::Touch(logfile.c_str(), true); cmSystemTools::Touch(logfile, true);
} }
return RETVAL; return RETVAL;

View File

@ -81,14 +81,14 @@ int testGeneratedFileStream(int, char* [])
cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ",
file1.c_str()); file1.c_str());
} }
cmSystemTools::RemoveFile(file1.c_str()); cmSystemTools::RemoveFile(file1);
cmSystemTools::RemoveFile(file2.c_str()); cmSystemTools::RemoveFile(file2);
cmSystemTools::RemoveFile(file3.c_str()); cmSystemTools::RemoveFile(file3);
cmSystemTools::RemoveFile(file4.c_str()); cmSystemTools::RemoveFile(file4);
cmSystemTools::RemoveFile(file1tmp.c_str()); cmSystemTools::RemoveFile(file1tmp);
cmSystemTools::RemoveFile(file2tmp.c_str()); cmSystemTools::RemoveFile(file2tmp);
cmSystemTools::RemoveFile(file3tmp.c_str()); cmSystemTools::RemoveFile(file3tmp);
cmSystemTools::RemoveFile(file4tmp.c_str()); cmSystemTools::RemoveFile(file4tmp);
return failed; return failed;
} }