Skip to content

Commit 36bf3f6

Browse files
committed
enabled and mitigated performance-avoid-endl clang-tidy warnings
1 parent 4567352 commit 36bf3f6

26 files changed

Lines changed: 253 additions & 255 deletions

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Checks: >
5252
-modernize-use-designated-initializers,
5353
-modernize-use-nodiscard,
5454
-modernize-use-trailing-return-type,
55-
-performance-avoid-endl,
5655
-performance-inefficient-string-concatenation,
5756
-performance-no-automatic-move,
5857
-portability-simd-intrinsics,

clang-tidy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
120120
`bugprone-signed-char-misuse`<br/>
121121
`concurrency-mt-unsafe`<br/>
122122
`misc-use-anonymous-namespace`<br/>
123-
`performance-avoid-endl`<br/>
124123
`bugprone-switch-missing-default-case`<br/>
125124
`bugprone-empty-catch`<br/>
126125
`readability-avoid-nested-conditional-operator`<br/>

cli/cmdlineparser.cpp

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

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

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

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

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

400400
// TODO: remove filename parameter?
@@ -501,11 +501,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
501501
#else
502502
FILE *p = popen(cmd.c_str(), "r");
503503
#endif
504-
//std::cout << "invoking command '" << cmd << "'" << std::endl;
504+
//std::cout << "invoking command '" << cmd << "'" << '\n';
505505
if (!p) {
506506
// TODO: how to provide to caller?
507507
//const int err = errno;
508-
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
508+
//std::cout << "popen() errno " << std::to_string(err) << '\n';
509509
return -1;
510510
}
511511
char buffer[1024];
@@ -520,7 +520,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
520520
if (res == -1) { // error occurred
521521
// TODO: how to provide to caller?
522522
//const int err = errno;
523-
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
523+
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
524524
return res;
525525
}
526526
#if !defined(WIN32) && !defined(__MINGW32__)

cli/processexecutor.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ namespace {
9797
const ssize_t bytes_written = write(mWpipe, data, to_write);
9898
if (bytes_written <= 0) {
9999
const int err = errno;
100-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
100+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << '\n';
101101
std::exit(EXIT_FAILURE);
102102
}
103103
// TODO: write until everything is written
104104
if (bytes_written != to_write) {
105-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
105+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
106106
std::exit(EXIT_FAILURE);
107107
}
108108
}
@@ -146,12 +146,12 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
146146
return false;
147147
}
148148
if (bytes_read != bytes_to_read) {
149-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
149+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
150150
std::exit(EXIT_FAILURE);
151151
}
152152

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

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

@@ -175,7 +175,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
175175
bytes_read = read(rpipe, data_start, bytes_to_read);
176176
if (bytes_read <= 0) {
177177
const int err = errno;
178-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
178+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << '\n';
179179
std::exit(EXIT_FAILURE);
180180
}
181181
bytes_to_read -= bytes_read;
@@ -193,7 +193,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
193193
try {
194194
msg.deserialize(buf);
195195
} catch (const InternalError& e) {
196-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << std::endl;
196+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << '\n';
197197
std::exit(EXIT_FAILURE);
198198
}
199199

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

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

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

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

cli/threadexecutor.cpp

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

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(fs.filename()) << std::endl;
63+
fout << afile << ".a" << (++fileCount[afile]) << ":" << fs.cfg << ":" << Path::simplifyPath(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: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
138138
{
139139
std::ostringstream fout;
140140

141-
fout << "Critical errors" << std::endl;
142-
fout << "---------------" << std::endl;
141+
fout << "Critical errors" << '\n';
142+
fout << "---------------" << '\n';
143143
if (!criticalErrors.empty()) {
144-
fout << "There was critical errors (" << criticalErrors << ")" << std::endl;
145-
fout << "All checking is skipped for a file with such error" << std::endl;
144+
fout << "There was critical errors (" << criticalErrors << ")" << '\n';
145+
fout << "All checking is skipped for a file with such error" << '\n';
146146
} else {
147-
fout << "No critical errors, all files were checked." << std::endl;
148-
fout << "Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives." << std::endl;
147+
fout << "No critical errors, all files were checked." << '\n';
148+
fout << "Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives." << '\n';
149149
}
150150

151-
fout << std::endl << std::endl;
152-
fout << "Open source checkers" << std::endl;
153-
fout << "--------------------" << std::endl;
151+
fout << '\n' << '\n';
152+
fout << "Open source checkers" << '\n';
153+
fout << "--------------------" << '\n';
154154

155155
std::size_t maxCheckerSize = 0;
156156
for (const auto& checkReq: checkers::allCheckers) {
@@ -164,7 +164,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
164164
fout << (active ? "Yes " : "No ") << checker;
165165
if (!active && !req.empty())
166166
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
167-
fout << std::endl;
167+
fout << '\n';
168168
}
169169

170170
const bool cppcheckPremium = isCppcheckPremium(mSettings);
@@ -175,11 +175,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
175175
const std::set<std::string>& activeCheckers,
176176
const std::map<std::string, std::string>& premiumCheckers,
177177
const std::string& substring) {
178-
fout << std::endl << std::endl;
179-
fout << title << std::endl;
180-
fout << std::string(title.size(), '-') << std::endl;
178+
fout << '\n' << '\n';
179+
fout << title << '\n';
180+
fout << std::string(title.size(), '-') << '\n';
181181
if (!cppcheckPremium) {
182-
fout << "Not available, Cppcheck Premium is not used" << std::endl;
182+
fout << "Not available, Cppcheck Premium is not used" << '\n';
183183
return;
184184
}
185185
int maxCheckerSize = 0;
@@ -215,7 +215,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
215215
req = "require:" + req;
216216
if (!active)
217217
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << req;
218-
fout << std::endl;
218+
fout << '\n';
219219
}
220220
};
221221

@@ -233,10 +233,10 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
233233
misra = 2012;
234234

235235
if (misra == 0) {
236-
fout << std::endl << std::endl;
237-
fout << "Misra C" << std::endl;
238-
fout << "-------" << std::endl;
239-
fout << "Misra is not enabled" << std::endl;
236+
fout << '\n' << '\n';
237+
fout << "Misra C" << '\n';
238+
fout << "-------" << '\n';
239+
fout << "Misra is not enabled" << '\n';
240240
} else {
241241
fout << std::endl << std::endl;
242242
fout << "Misra C " << misra << std::endl;

0 commit comments

Comments
 (0)