Skip to content

Commit a0fac37

Browse files
committed
enabled and mitigated performance-avoid-endl clang-tidy warnings
1 parent 6c58be6 commit a0fac37

27 files changed

+266
-268
lines changed

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Checks: >
5050
-modernize-use-auto,
5151
-modernize-use-nodiscard,
5252
-modernize-use-trailing-return-type,
53-
-performance-avoid-endl,
5453
-performance-enum-size,
5554
-performance-inefficient-string-concatenation,
5655
-performance-no-automatic-move,

clang-tidy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
125125
`readability-redundant-access-specifiers`<br/>
126126
`concurrency-mt-unsafe`<br/>
127127
`misc-use-anonymous-namespace`<br/>
128-
`performance-avoid-endl`<br/>
129128
`performance-noexcept-swap`<br/>
130129
`bugprone-switch-missing-default-case`<br/>
131130
`bugprone-empty-catch`<br/>

cli/cmdlineparser.cpp

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

128128
void reportErr(const ErrorMessage &msg) override
@@ -175,7 +175,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
175175
// TODO: this bypasses the template format and other settings
176176
// If the include path is not found, warn user and remove the non-existing path from the list.
177177
if (mSettings.severity.isEnabled(Severity::information))
178-
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
178+
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << '\n';
179179
iter = mSettings.includePaths.erase(iter);
180180
}
181181
}
@@ -342,7 +342,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
342342
XMLErrorMessagesLogger xmlLogger;
343343
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName);
344344
CppCheck::getErrorMessages(xmlLogger);
345-
std::cout << ErrorMessage::getXMLFooter() << std::endl;
345+
std::cout << ErrorMessage::getXMLFooter() << '\n';
346346
}
347347
return Result::Exit;
348348
}

cli/cppcheckexecutor.cpp

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

8989
void printRaw(const std::string &message) override
9090
{
91-
std::cout << message << std::endl;
91+
std::cout << message << '\n';
9292
}
9393
};
9494

@@ -381,18 +381,18 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
381381
void StdLogger::reportErr(const std::string &errmsg)
382382
{
383383
if (mErrorOutput)
384-
*mErrorOutput << errmsg << std::endl;
384+
*mErrorOutput << errmsg << '\n';
385385
else {
386-
std::cerr << ansiToOEM(errmsg, !mSettings.xml) << std::endl;
386+
std::cerr << ansiToOEM(errmsg, !mSettings.xml) << '\n';
387387
}
388388
}
389389

390390
void StdLogger::reportOut(const std::string &outmsg, Color c)
391391
{
392392
if (c == Color::Reset)
393-
std::cout << ansiToOEM(outmsg, true) << std::endl;
393+
std::cout << ansiToOEM(outmsg, true) << '\n';
394394
else
395-
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
395+
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << '\n';
396396
}
397397

398398
// TODO: remove filename parameter?
@@ -499,11 +499,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
499499
#else
500500
FILE *p = popen(cmd.c_str(), "r");
501501
#endif
502-
//std::cout << "invoking command '" << cmd << "'" << std::endl;
502+
//std::cout << "invoking command '" << cmd << "'" << '\n';
503503
if (!p) {
504504
// TODO: how to provide to caller?
505505
//const int err = errno;
506-
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
506+
//std::cout << "popen() errno " << std::to_string(err) << '\n';
507507
return -1;
508508
}
509509
char buffer[1024];
@@ -518,7 +518,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
518518
if (res == -1) { // error occurred
519519
// TODO: how to provide to caller?
520520
//const int err = errno;
521-
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
521+
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
522522
return res;
523523
}
524524
#if !defined(WIN32) && !defined(__MINGW32__)

cli/processexecutor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ namespace {
9595
const ssize_t bytes_written = write(mWpipe, data, to_write);
9696
if (bytes_written <= 0) {
9797
const int err = errno;
98-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
98+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << '\n';
9999
std::exit(EXIT_FAILURE);
100100
}
101101
// TODO: write until everything is written
102102
if (bytes_written != to_write) {
103-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
103+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
104104
std::exit(EXIT_FAILURE);
105105
}
106106
}
@@ -144,12 +144,12 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
144144
return false;
145145
}
146146
if (bytes_read != bytes_to_read) {
147-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
147+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
148148
std::exit(EXIT_FAILURE);
149149
}
150150

151151
if (type != PipeWriter::REPORT_OUT && type != PipeWriter::REPORT_ERROR && type != PipeWriter::CHILD_END) {
152-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << std::endl;
152+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << '\n';
153153
std::exit(EXIT_FAILURE);
154154
}
155155

@@ -158,11 +158,11 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
158158
bytes_read = read(rpipe, &len, bytes_to_read);
159159
if (bytes_read <= 0) {
160160
const int err = errno;
161-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << std::endl;
161+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << '\n';
162162
std::exit(EXIT_FAILURE);
163163
}
164164
if (bytes_read != bytes_to_read) {
165-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
165+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
166166
std::exit(EXIT_FAILURE);
167167
}
168168

@@ -173,7 +173,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
173173
bytes_read = read(rpipe, data_start, bytes_to_read);
174174
if (bytes_read <= 0) {
175175
const int err = errno;
176-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
176+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << '\n';
177177
std::exit(EXIT_FAILURE);
178178
}
179179
bytes_to_read -= bytes_read;
@@ -191,7 +191,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
191191
try {
192192
msg.deserialize(buf);
193193
} catch (const InternalError& e) {
194-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << std::endl;
194+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << '\n';
195195
std::exit(EXIT_FAILURE);
196196
}
197197

@@ -248,25 +248,25 @@ unsigned int ProcessExecutor::check()
248248
if ((iFile != mFiles.cend() || iFileSettings != mFileSettings.cend()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
249249
int pipes[2];
250250
if (pipe(pipes) == -1) {
251-
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
251+
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << '\n';
252252
std::exit(EXIT_FAILURE);
253253
}
254254

255255
const int flags = fcntl(pipes[0], F_GETFL, 0);
256256
if (flags < 0) {
257-
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
257+
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << '\n';
258258
std::exit(EXIT_FAILURE);
259259
}
260260

261261
if (fcntl(pipes[0], F_SETFL, flags) < 0) {
262-
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
262+
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << '\n';
263263
std::exit(EXIT_FAILURE);
264264
}
265265

266266
const pid_t pid = fork();
267267
if (pid < 0) {
268268
// Error
269-
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
269+
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << '\n';
270270
std::exit(EXIT_FAILURE);
271271
} else if (pid == 0) {
272272
#if defined(__linux__)

cli/threadexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ unsigned int ThreadExecutor::check()
187187
threadFutures.emplace_back(std::async(std::launch::async, &threadProc, &data));
188188
}
189189
catch (const std::system_error &e) {
190-
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << std::endl;
190+
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << '\n';
191191
exit(EXIT_FAILURE);
192192
}
193193
}

gui/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void ShowUsage()
124124
);
125125
(void)msgBox.exec();
126126
#else
127-
std::cout << helpMessage.toStdString() << std::endl;
127+
std::cout << helpMessage.toStdString() << '\n';
128128
#endif
129129
}
130130

@@ -141,6 +141,6 @@ static void ShowVersion()
141141
if (*extraVersion != 0)
142142
versionMessage += std::string(" (") + extraVersion + ")";
143143

144-
std::cout << versionMessage << std::endl;
144+
std::cout << versionMessage << '\n';
145145
#endif
146146
}

lib/analyzerinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::
6060

6161
for (const FileSettings &fs : fileSettings) {
6262
const std::string afile = getFilename(fs.filename);
63-
fout << afile << ".a" << (++fileCount[afile]) << ":" << fs.cfg << ":" << Path::simplifyPath(Path::fromNativeSeparators(fs.filename)) << std::endl;
63+
fout << afile << ".a" << (++fileCount[afile]) << ":" << fs.cfg << ":" << Path::simplifyPath(Path::fromNativeSeparators(fs.filename)) << '\n';
6464
}
6565
}
6666

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: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,19 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
104104
{
105105
std::ostringstream fout;
106106

107-
fout << "Critical errors" << std::endl;
108-
fout << "---------------" << std::endl;
107+
fout << "Critical errors" << '\n';
108+
fout << "---------------" << '\n';
109109
if (!criticalErrors.empty()) {
110-
fout << "There was critical errors (" << criticalErrors << ")" << std::endl;
111-
fout << "All checking is skipped for a file with such error" << std::endl;
110+
fout << "There was critical errors (" << criticalErrors << ")" << '\n';
111+
fout << "All checking is skipped for a file with such error" << '\n';
112112
} else {
113-
fout << "No critical errors, all files were checked." << std::endl;
114-
fout << "Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives." << std::endl;
113+
fout << "No critical errors, all files were checked." << '\n';
114+
fout << "Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives." << '\n';
115115
}
116116

117-
fout << std::endl << std::endl;
118-
fout << "Open source checkers" << std::endl;
119-
fout << "--------------------" << std::endl;
117+
fout << '\n' << '\n';
118+
fout << "Open source checkers" << '\n';
119+
fout << "--------------------" << '\n';
120120

121121
int maxCheckerSize = 0;
122122
for (const auto& checkReq: checkers::allCheckers) {
@@ -131,7 +131,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
131131
fout << (active ? "Yes " : "No ") << checker;
132132
if (!active && !req.empty())
133133
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
134-
fout << std::endl;
134+
fout << '\n';
135135
}
136136

137137
const bool cppcheckPremium = isCppcheckPremium(mSettings);
@@ -142,11 +142,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
142142
const std::set<std::string>& activeCheckers,
143143
const std::map<std::string, std::string>& premiumCheckers,
144144
const std::string& substring) {
145-
fout << std::endl << std::endl;
146-
fout << title << std::endl;
147-
fout << std::string(title.size(), '-') << std::endl;
145+
fout << '\n' << '\n';
146+
fout << title << '\n';
147+
fout << std::string(title.size(), '-') << '\n';
148148
if (!cppcheckPremium) {
149-
fout << "Not available, Cppcheck Premium is not used" << std::endl;
149+
fout << "Not available, Cppcheck Premium is not used" << '\n';
150150
return;
151151
}
152152
int maxCheckerSize = 0;
@@ -174,7 +174,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
174174
req = "premium";
175175
if (!active)
176176
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
177-
fout << std::endl;
177+
fout << '\n';
178178
}
179179
};
180180

@@ -192,14 +192,14 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
192192
misra = 2012;
193193

194194
if (misra == 0) {
195-
fout << std::endl << std::endl;
196-
fout << "Misra C" << std::endl;
197-
fout << "-------" << std::endl;
198-
fout << "Misra is not enabled" << std::endl;
195+
fout << '\n' << '\n';
196+
fout << "Misra C" << '\n';
197+
fout << "-------" << '\n';
198+
fout << "Misra is not enabled" << '\n';
199199
} else {
200-
fout << std::endl << std::endl;
201-
fout << "Misra C " << misra << std::endl;
202-
fout << "------------" << std::endl;
200+
fout << '\n' << '\n';
201+
fout << "Misra C " << misra << '\n';
202+
fout << "------------" << '\n';
203203
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
204204
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
205205
const std::string severity = getMisraRuleSeverity(rule);

0 commit comments

Comments
 (0)