Skip to content

Commit 2236046

Browse files
committed
enabled and mitigated performance-avoid-endl clang-tidy warnings
1 parent 1f55dff commit 2236046

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
@@ -119,7 +119,7 @@ namespace {
119119
{
120120
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
121121
{
122-
std::cout << outmsg << std::endl;
122+
std::cout << outmsg << '\n';
123123
}
124124

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

cli/cppcheckexecutor.cpp

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

236236
void printRaw(const std::string &message) override
237237
{
238-
std::cout << message << std::endl;
238+
std::cout << message << '\n';
239239
}
240240
};
241241

@@ -551,18 +551,18 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
551551
void StdLogger::reportErr(const std::string &errmsg)
552552
{
553553
if (mErrorOutput)
554-
*mErrorOutput << errmsg << std::endl;
554+
*mErrorOutput << errmsg << '\n';
555555
else {
556-
std::cerr << ansiToOEM(errmsg, !mSettings.xml) << std::endl;
556+
std::cerr << ansiToOEM(errmsg, !mSettings.xml) << '\n';
557557
}
558558
}
559559

560560
void StdLogger::reportOut(const std::string &outmsg, Color c)
561561
{
562562
if (c == Color::Reset)
563-
std::cout << ansiToOEM(outmsg, true) << std::endl;
563+
std::cout << ansiToOEM(outmsg, true) << '\n';
564564
else
565-
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
565+
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << '\n';
566566
}
567567

568568
// TODO: remove filename parameter?
@@ -660,11 +660,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
660660
#else
661661
FILE *p = popen(cmd.c_str(), "r");
662662
#endif
663-
//std::cout << "invoking command '" << cmd << "'" << std::endl;
663+
//std::cout << "invoking command '" << cmd << "'" << '\n';
664664
if (!p) {
665665
// TODO: how to provide to caller?
666666
//const int err = errno;
667-
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
667+
//std::cout << "popen() errno " << std::to_string(err) << '\n';
668668
return -1;
669669
}
670670
char buffer[1024];
@@ -679,7 +679,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
679679
if (res == -1) { // error occurred
680680
// TODO: how to provide to caller?
681681
//const int err = errno;
682-
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
682+
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
683683
return res;
684684
}
685685
#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
@@ -154,23 +154,23 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
154154
{
155155
std::ostringstream fout;
156156

157-
fout << "Critical errors" << std::endl;
158-
fout << "---------------" << std::endl;
157+
fout << "Critical errors" << '\n';
158+
fout << "---------------" << '\n';
159159
if (!criticalErrors.empty()) {
160-
fout << "There were critical errors (" << criticalErrors << ")." << std::endl;
161-
fout << "These cause the analysis of the file to end prematurely." << std::endl;
160+
fout << "There were critical errors (" << criticalErrors << ")." << '\n';
161+
fout << "These cause the analysis of the file to end prematurely." << '\n';
162162
} else {
163-
fout << "No critical errors encountered." << std::endl;
163+
fout << "No critical errors encountered." << '\n';
164164
// TODO: mention "information" and "debug" as source for indications of bailouts
165165
// TODO: still rephrase this - this message does not provides confidence in the results
166166
// TODO: document what a bailout is and why it is done - mention it in the upcoming security/tuning guide
167167
// 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)
168-
fout << "Note: There might still have been non-critical bailouts which might lead to false negatives." << std::endl;
168+
fout << "Note: There might still have been non-critical bailouts which might lead to false negatives." << '\n';
169169
}
170170

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

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

190190
const bool cppcheckPremium = isCppcheckPremium(mSettings);
@@ -195,11 +195,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
195195
const std::set<std::string>& activeCheckers,
196196
const std::map<std::string, std::string>& premiumCheckers,
197197
const std::string& substring) {
198-
fout << std::endl << std::endl;
199-
fout << title << std::endl;
200-
fout << std::string(title.size(), '-') << std::endl;
198+
fout << '\n' << '\n';
199+
fout << title << '\n';
200+
fout << std::string(title.size(), '-') << '\n';
201201
if (!cppcheckPremium) {
202-
fout << "Not available, Cppcheck Premium is not used" << std::endl;
202+
fout << "Not available, Cppcheck Premium is not used" << '\n';
203203
return;
204204
}
205205
int maxCheckerSize = 0;
@@ -235,7 +235,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
235235
req = "require:" + req;
236236
if (!active)
237237
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << req;
238-
fout << std::endl;
238+
fout << '\n';
239239
}
240240
};
241241

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

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

0 commit comments

Comments
 (0)