Skip to content

Commit 179df83

Browse files
committed
enabled and mitigated performance-avoid-endl clang-tidy warnings
1 parent 8ca7033 commit 179df83

25 files changed

Lines changed: 236 additions & 238 deletions

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Checks: >
5151
-modernize-use-designated-initializers,
5252
-modernize-use-nodiscard,
5353
-modernize-use-trailing-return-type,
54-
-performance-avoid-endl,
5554
-performance-inefficient-string-concatenation,
5655
-performance-no-automatic-move,
5756
-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
@@ -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
@@ -173,7 +173,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
173173
// TODO: this bypasses the template format and other settings
174174
// If the include path is not found, warn user and remove the non-existing path from the list.
175175
if (mSettings.severity.isEnabled(Severity::information))
176-
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
176+
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << '\n';
177177
iter = mSettings.includePaths.erase(iter);
178178
}
179179
}
@@ -411,7 +411,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
411411
XMLErrorMessagesLogger xmlLogger;
412412
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName, 2);
413413
CppCheck::getErrorMessages(xmlLogger);
414-
std::cout << ErrorMessage::getXMLFooter(2) << std::endl;
414+
std::cout << ErrorMessage::getXMLFooter(2) << '\n';
415415
}
416416
return Result::Exit;
417417
}

cli/cppcheckexecutor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ namespace {
241241

242242
void printRaw(const std::string &message) override
243243
{
244-
std::cout << message << std::endl;
244+
std::cout << message << '\n';
245245
}
246246
};
247247

@@ -564,7 +564,7 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
564564
void StdLogger::reportErr(const std::string &errmsg)
565565
{
566566
if (mErrorOutput)
567-
*mErrorOutput << errmsg << std::endl;
567+
*mErrorOutput << errmsg << '\n';
568568
else {
569569
std::cerr << ansiToOEM(errmsg, mSettings.outputFormat != Settings::OutputFormat::xml) << std::endl;
570570
}
@@ -573,9 +573,9 @@ void StdLogger::reportErr(const std::string &errmsg)
573573
void StdLogger::reportOut(const std::string &outmsg, Color c)
574574
{
575575
if (c == Color::Reset)
576-
std::cout << ansiToOEM(outmsg, true) << std::endl;
576+
std::cout << ansiToOEM(outmsg, true) << '\n';
577577
else
578-
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
578+
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << '\n';
579579
}
580580

581581
// TODO: remove filename parameter?
@@ -678,11 +678,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
678678
#else
679679
FILE *p = popen(cmd.c_str(), "r");
680680
#endif
681-
//std::cout << "invoking command '" << cmd << "'" << std::endl;
681+
//std::cout << "invoking command '" << cmd << "'" << '\n';
682682
if (!p) {
683683
// TODO: how to provide to caller?
684684
//const int err = errno;
685-
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
685+
//std::cout << "popen() errno " << std::to_string(err) << '\n';
686686
return -1;
687687
}
688688
char buffer[1024];
@@ -697,7 +697,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
697697
if (res == -1) { // error occurred
698698
// TODO: how to provide to caller?
699699
//const int err = errno;
700-
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
700+
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
701701
return res;
702702
}
703703
#if !defined(WIN32) && !defined(__MINGW32__)

cli/processexecutor.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ namespace {
101101
const ssize_t bytes_written = write(mWpipe, data, to_write);
102102
if (bytes_written <= 0) {
103103
const int err = errno;
104-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
104+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << '\n';
105105
std::exit(EXIT_FAILURE);
106106
}
107107
// TODO: write until everything is written
108108
if (bytes_written != to_write) {
109-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
109+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
110110
std::exit(EXIT_FAILURE);
111111
}
112112
}
@@ -151,12 +151,12 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
151151
return false;
152152
}
153153
if (bytes_read != bytes_to_read) {
154-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
154+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
155155
std::exit(EXIT_FAILURE);
156156
}
157157

158158
if (type != PipeWriter::REPORT_OUT && type != PipeWriter::REPORT_ERROR && type != PipeWriter::CHILD_END) {
159-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << std::endl;
159+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << '\n';
160160
std::exit(EXIT_FAILURE);
161161
}
162162

@@ -165,11 +165,11 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
165165
bytes_read = read(rpipe, &len, bytes_to_read);
166166
if (bytes_read <= 0) {
167167
const int err = errno;
168-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << std::endl;
168+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << '\n';
169169
std::exit(EXIT_FAILURE);
170170
}
171171
if (bytes_read != bytes_to_read) {
172-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
172+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
173173
std::exit(EXIT_FAILURE);
174174
}
175175

@@ -200,7 +200,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
200200
try {
201201
msg.deserialize(buf);
202202
} catch (const InternalError& e) {
203-
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << std::endl;
203+
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << '\n';
204204
std::exit(EXIT_FAILURE);
205205
}
206206

@@ -257,25 +257,25 @@ unsigned int ProcessExecutor::check()
257257
if ((iFile != mFiles.cend() || iFileSettings != mFileSettings.cend()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
258258
int pipes[2];
259259
if (pipe(pipes) == -1) {
260-
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
260+
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << '\n';
261261
std::exit(EXIT_FAILURE);
262262
}
263263

264264
const int flags = fcntl(pipes[0], F_GETFL, 0);
265265
if (flags < 0) {
266-
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
266+
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << '\n';
267267
std::exit(EXIT_FAILURE);
268268
}
269269

270270
if (fcntl(pipes[0], F_SETFL, flags) < 0) {
271-
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
271+
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << '\n';
272272
std::exit(EXIT_FAILURE);
273273
}
274274

275275
const pid_t pid = fork();
276276
if (pid < 0) {
277277
// Error
278-
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
278+
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << '\n';
279279
std::exit(EXIT_FAILURE);
280280
} else if (pid == 0) {
281281
#if defined(__linux__)

cli/threadexecutor.cpp

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

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
@@ -155,23 +155,23 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
155155
{
156156
std::ostringstream fout;
157157

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

172-
fout << std::endl << std::endl;
173-
fout << "Open source checkers" << std::endl;
174-
fout << "--------------------" << std::endl;
172+
fout << '\n' << '\n';
173+
fout << "Open source checkers" << '\n';
174+
fout << "--------------------" << '\n';
175175

176176
std::size_t maxCheckerSize = 0;
177177
for (const auto& checkReq: checkers::allCheckers) {
@@ -185,7 +185,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
185185
fout << (active ? "Yes " : "No ") << checker;
186186
if (!active && !req.empty())
187187
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
188-
fout << std::endl;
188+
fout << '\n';
189189
}
190190

191191
const bool cppcheckPremium = isCppcheckPremium(mSettings);
@@ -196,11 +196,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
196196
const std::set<std::string>& activeCheckers,
197197
const std::map<std::string, std::string>& premiumCheckers,
198198
const std::string& substring) {
199-
fout << std::endl << std::endl;
200-
fout << title << std::endl;
201-
fout << std::string(title.size(), '-') << std::endl;
199+
fout << '\n' << '\n';
200+
fout << title << '\n';
201+
fout << std::string(title.size(), '-') << '\n';
202202
if (!cppcheckPremium) {
203-
fout << "Not available, Cppcheck Premium is not used" << std::endl;
203+
fout << "Not available, Cppcheck Premium is not used" << '\n';
204204
return;
205205
}
206206
int maxCheckerSize = 0;
@@ -236,7 +236,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
236236
req = "require:" + req;
237237
if (!active)
238238
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << req;
239-
fout << std::endl;
239+
fout << '\n';
240240
}
241241
};
242242

@@ -248,10 +248,10 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
248248
const int misraCVersion = getMisraCVersion(mSettings);
249249

250250
if (misraCVersion == 0) {
251-
fout << std::endl << std::endl;
252-
fout << "Misra C" << std::endl;
253-
fout << "-------" << std::endl;
254-
fout << "Misra is not enabled" << std::endl;
251+
fout << '\n' << '\n';
252+
fout << "Misra C" << '\n';
253+
fout << "-------" << '\n';
254+
fout << "Misra is not enabled" << '\n';
255255
} else {
256256
fout << std::endl << std::endl;
257257
fout << "Misra C " << misraCVersion << std::endl;

0 commit comments

Comments
 (0)