Skip to content

Commit 667178b

Browse files
committed
enabled and mitigated performance-avoid-endl clang-tidy warnings
1 parent 6278f6b commit 667178b

25 files changed

Lines changed: 248 additions & 250 deletions

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ Checks: >
5555
-modernize-use-nodiscard,
5656
-modernize-use-scoped-lock,
5757
-modernize-use-trailing-return-type,
58-
-performance-avoid-endl,
5958
-performance-inefficient-string-concatenation,
6059
-performance-no-automatic-move,
6160
-portability-avoid-pragma-once,

clang-tidy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ Does not improve the readability.
123123
`bugprone-signed-char-misuse`<br/>
124124
`concurrency-mt-unsafe`<br/>
125125
`misc-use-anonymous-namespace`<br/>
126-
`performance-avoid-endl`<br/>
127126
`bugprone-switch-missing-default-case`<br/>
128127
`bugprone-empty-catch`<br/>
129128
`readability-avoid-nested-conditional-operator`<br/>

cli/cmdlineparser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace {
120120
{
121121
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
122122
{
123-
std::cout << outmsg << std::endl;
123+
std::cout << outmsg << '\n';
124124
}
125125

126126
void reportErr(const ErrorMessage &msg) override
@@ -179,7 +179,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
179179
// TODO: this bypasses the template format and other settings
180180
// If the include path is not found, warn user and remove the non-existing path from the list.
181181
if (mSettings.severity.isEnabled(Severity::information))
182-
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
182+
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << '\n';
183183
iter = mSettings.includePaths.erase(iter);
184184
}
185185
}
@@ -377,7 +377,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
377377
XMLErrorMessagesLogger xmlLogger;
378378
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName, 2);
379379
CppCheck::getErrorMessages(xmlLogger);
380-
std::cout << ErrorMessage::getXMLFooter(2) << std::endl;
380+
std::cout << ErrorMessage::getXMLFooter(2) << '\n';
381381
}
382382
return Result::Exit;
383383
}

cli/cppcheckexecutor.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace {
9797

9898
void printRaw(const std::string &message) override
9999
{
100-
std::cout << message << std::endl; // TODO: should not append newline
100+
std::cout << message << '\n'; // TODO: should not append newline
101101
}
102102
};
103103

@@ -592,18 +592,18 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
592592
void StdLogger::reportErr(const std::string &errmsg)
593593
{
594594
if (mErrorOutput)
595-
*mErrorOutput << errmsg << std::endl;
595+
*mErrorOutput << errmsg << '\n';
596596
else {
597-
std::cerr << ansiToOEM(errmsg, mSettings.outputFormat != Settings::OutputFormat::xml) << std::endl;
597+
std::cerr << ansiToOEM(errmsg, mSettings.outputFormat != Settings::OutputFormat::xml) << '\n';
598598
}
599599
}
600600

601601
void StdLogger::reportOut(const std::string &outmsg, Color c)
602602
{
603603
if (c == Color::Reset)
604-
std::cout << ansiToOEM(outmsg, true) << std::endl;
604+
std::cout << ansiToOEM(outmsg, true) << '\n';
605605
else
606-
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
606+
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << '\n';
607607
}
608608

609609
// TODO: remove filename parameter?
@@ -710,11 +710,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
710710
#else
711711
FILE *p = popen(cmd.c_str(), "r");
712712
#endif
713-
//std::cout << "invoking command '" << cmd << "'" << std::endl;
713+
//std::cout << "invoking command '" << cmd << "'" << '\n';
714714
if (!p) {
715715
// TODO: how to provide to caller?
716716
//const int err = errno;
717-
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
717+
//std::cout << "popen() errno " << std::to_string(err) << '\n';
718718
return -1;
719719
}
720720
char buffer[1024];
@@ -732,7 +732,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
732732
if (res == -1) { // error occurred
733733
// TODO: how to provide to caller?
734734
//const int err = errno;
735-
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
735+
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
736736
return res;
737737
}
738738
#if !defined(_WIN32) && !defined(__MINGW32__)

cli/processexecutor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ namespace {
141141
const ssize_t bytes_written = write(mWpipe, data, to_write);
142142
if (bytes_written <= 0) {
143143
const int err = errno;
144-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": " << std::strerror(err) << std::endl;
144+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": " << std::strerror(err) << '\n';
145145
std::exit(EXIT_FAILURE);
146146
}
147147
// TODO: write until everything is written
148148
if (bytes_written != to_write) {
149-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
149+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
150150
std::exit(EXIT_FAILURE);
151151
}
152152
}
@@ -191,7 +191,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
191191
return false;
192192
}
193193
if (bytes_read != bytes_to_read) {
194-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
194+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
195195
std::exit(EXIT_FAILURE);
196196
}
197197

@@ -202,7 +202,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
202202
type != PipeWriter::CHILD_END &&
203203
type != PipeWriter::REPORT_METRIC &&
204204
type != PipeWriter::REPORT_TIMER) {
205-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << std::endl;
205+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << '\n';
206206
std::exit(EXIT_FAILURE);
207207
}
208208

@@ -211,11 +211,11 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
211211
bytes_read = read(rpipe, &len, bytes_to_read);
212212
if (bytes_read <= 0) {
213213
const int err = errno;
214-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << std::endl;
214+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << '\n';
215215
std::exit(EXIT_FAILURE);
216216
}
217217
if (bytes_read != bytes_to_read) {
218-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
218+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
219219
std::exit(EXIT_FAILURE);
220220
}
221221

@@ -227,7 +227,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
227227
bytes_read = read(rpipe, data_start, bytes_to_read);
228228
if (bytes_read <= 0) {
229229
const int err = errno;
230-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
230+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << '\n';
231231
std::exit(EXIT_FAILURE);
232232
}
233233
bytes_to_read -= bytes_read;
@@ -246,7 +246,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
246246
try {
247247
msg.deserialize(buf);
248248
} catch (const InternalError& e) {
249-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << std::endl;
249+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << '\n';
250250
std::exit(EXIT_FAILURE);
251251
}
252252

@@ -347,25 +347,25 @@ unsigned int ProcessExecutor::check()
347347
if ((iFile != mFiles.cend() || iFileSettings != mFileSettings.cend()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
348348
int pipes[2];
349349
if (pipe(pipes) == -1) {
350-
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
350+
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << '\n';
351351
std::exit(EXIT_FAILURE);
352352
}
353353

354354
const int flags = fcntl(pipes[0], F_GETFL, 0);
355355
if (flags < 0) {
356-
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
356+
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << '\n';
357357
std::exit(EXIT_FAILURE);
358358
}
359359

360360
if (fcntl(pipes[0], F_SETFL, flags) < 0) {
361-
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
361+
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << '\n';
362362
std::exit(EXIT_FAILURE);
363363
}
364364

365365
const pid_t pid = fork();
366366
if (pid < 0) {
367367
// Error
368-
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
368+
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << '\n';
369369
std::exit(EXIT_FAILURE);
370370
} else if (pid == 0) {
371371
#if defined(__linux__)

cli/threadexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ unsigned int ThreadExecutor::check()
207207
threadFutures.emplace_back(std::async(std::launch::async, &threadProc, &data));
208208
}
209209
catch (const std::system_error &e) {
210-
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << std::endl;
210+
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << '\n';
211211
exit(EXIT_FAILURE);
212212
}
213213
}

gui/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void ShowUsage()
118118
);
119119
(void)msgBox.exec();
120120
#else
121-
std::cout << helpMessage.toStdString() << std::endl;
121+
std::cout << helpMessage.toStdString() << '\n';
122122
#endif
123123
}
124124

@@ -136,6 +136,6 @@ static void ShowVersion()
136136
if (*extraVersion != 0)
137137
versionMessage += std::string(" (") + extraVersion + ")";
138138

139-
std::cout << versionMessage << std::endl;
139+
std::cout << versionMessage << '\n';
140140
#endif
141141
}

lib/analyzerinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ std::string AnalyzerInformation::getFilesTxt(const std::list<std::string> &sourc
7171
for (const FileSettings &fs : fileSettings) {
7272
const std::string afile = getFilename(fs.filename());
7373
const std::string id = fs.file.fsFileId() > 0 ? std::to_string(fs.file.fsFileId()) : "";
74-
ret << afile << ".a" << (++fileCount[afile]) << sep << fs.cfg << sep << id << sep << Path::simplifyPath(fs.filename()) << std::endl;
74+
ret << afile << ".a" << (++fileCount[afile]) << sep << fs.cfg << sep << id << sep << Path::simplifyPath(fs.filename()) << '\n';
7575
}
7676

7777
return ret.str();

lib/check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Check::Check(const std::string &aname)
5757

5858
void Check::writeToErrorList(const ErrorMessage &errmsg)
5959
{
60-
std::cout << errmsg.toXML() << std::endl;
60+
std::cout << errmsg.toXML() << '\n';
6161
}
6262

6363

lib/checkersreport.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,23 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
160160
{
161161
std::ostringstream fout;
162162

163-
fout << "Critical errors" << std::endl;
164-
fout << "---------------" << std::endl;
163+
fout << "Critical errors" << '\n';
164+
fout << "---------------" << '\n';
165165
if (!criticalErrors.empty()) {
166-
fout << "There were critical errors (" << criticalErrors << ")." << std::endl;
167-
fout << "These cause the analysis of the file to end prematurely." << std::endl;
166+
fout << "There were critical errors (" << criticalErrors << ")." << '\n';
167+
fout << "These cause the analysis of the file to end prematurely." << '\n';
168168
} else {
169-
fout << "No critical errors encountered." << std::endl;
169+
fout << "No critical errors encountered." << '\n';
170170
// TODO: mention "information" and "debug" as source for indications of bailouts
171171
// TODO: still rephrase this - this message does not provides confidence in the results
172172
// TODO: document what a bailout is and why it is done - mention it in the upcoming security/tuning guide
173173
// TODO: make bailouts a separate group - need to differentiate between user bailouts (missing data like configuration/includes) and internal bailouts (e.g. limitations of ValueFlow)
174-
fout << "Note: There might still have been non-critical bailouts which might lead to false negatives." << std::endl;
174+
fout << "Note: There might still have been non-critical bailouts which might lead to false negatives." << '\n';
175175
}
176176

177-
fout << std::endl << std::endl;
178-
fout << "Open source checkers" << std::endl;
179-
fout << "--------------------" << std::endl;
177+
fout << '\n' << '\n';
178+
fout << "Open source checkers" << '\n';
179+
fout << "--------------------" << '\n';
180180

181181
std::size_t maxCheckerSize = 0;
182182
for (const auto& checkReq: checkers::allCheckers) {
@@ -190,13 +190,13 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
190190
fout << (active ? "Yes " : "No ") << checker;
191191
if (!active && !req.empty())
192192
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
193-
fout << std::endl;
193+
fout << '\n';
194194
}
195195

196196
for (const auto& addonInfo: mSettings.addonInfos) {
197197
if (addonInfo.checkers.empty())
198198
continue;
199-
fout << std::endl << std::endl;
199+
fout << '\n'<< '\n';
200200
std::string title;
201201
if (mSettings.premium && addonInfo.name == "premiumaddon.json")
202202
title = "Cppcheck Premium";
@@ -206,8 +206,8 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
206206
title.erase(title.rfind('.'));
207207
}
208208
title += " checkers";
209-
fout << title << std::endl;
210-
fout << std::string(title.size(), '-') << std::endl;
209+
fout << title << '\n';
210+
fout << std::string(title.size(), '-') << '\n';
211211

212212
maxCheckerSize = 0;
213213
for (const auto& checkReq: addonInfo.checkers) {
@@ -222,7 +222,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
222222
fout << (active ? "Yes " : "No ") << checker;
223223
if (!active && !req.empty())
224224
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" << req;
225-
fout << std::endl;
225+
fout << '\n';
226226
}
227227
}
228228

0 commit comments

Comments
 (0)