Skip to content

Commit 1b3182a

Browse files
committed
enabled and mitigated performance-avoid-endl clang-tidy warnings
1 parent 8bced91 commit 1b3182a

26 files changed

Lines changed: 261 additions & 263 deletions

.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-inefficient-string-concatenation,
5554
-performance-no-automatic-move,
5655
-performance-noexcept-swap,

clang-tidy.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
121121
`bugprone-signed-char-misuse`<br/>
122122
`concurrency-mt-unsafe`<br/>
123123
`misc-use-anonymous-namespace`<br/>
124-
`performance-avoid-endl`<br/>
125124
`performance-noexcept-swap`<br/>
126125
`bugprone-switch-missing-default-case`<br/>
127126
`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
}
@@ -345,7 +345,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
345345
XMLErrorMessagesLogger xmlLogger;
346346
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName);
347347
CppCheck::getErrorMessages(xmlLogger);
348-
std::cout << ErrorMessage::getXMLFooter() << std::endl;
348+
std::cout << ErrorMessage::getXMLFooter() << '\n';
349349
}
350350
return Result::Exit;
351351
}

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
@@ -96,12 +96,12 @@ namespace {
9696
const ssize_t bytes_written = write(mWpipe, data, to_write);
9797
if (bytes_written <= 0) {
9898
const int err = errno;
99-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
99+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << '\n';
100100
std::exit(EXIT_FAILURE);
101101
}
102102
// TODO: write until everything is written
103103
if (bytes_written != to_write) {
104-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
104+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
105105
std::exit(EXIT_FAILURE);
106106
}
107107
}
@@ -145,12 +145,12 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
145145
return false;
146146
}
147147
if (bytes_read != bytes_to_read) {
148-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
148+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
149149
std::exit(EXIT_FAILURE);
150150
}
151151

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

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

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

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

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

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

267267
const pid_t pid = fork();
268268
if (pid < 0) {
269269
// Error
270-
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
270+
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << '\n';
271271
std::exit(EXIT_FAILURE);
272272
} else if (pid == 0) {
273273
#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: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,19 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
137137
{
138138
std::ostringstream fout;
139139

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

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

154154
int maxCheckerSize = 0;
155155
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,14 +233,14 @@ 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 {
241-
fout << std::endl << std::endl;
242-
fout << "Misra C " << misra << std::endl;
243-
fout << "------------" << std::endl;
241+
fout << '\n' << '\n';
242+
fout << "Misra C " << misra << '\n';
243+
fout << "------------" << '\n';
244244
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
245245
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
246246
const bool active = isMisraRuleActive(mActiveCheckers, rule);

0 commit comments

Comments
 (0)