Skip to content

Commit

Permalink
enabled and mitigated performance-avoid-endl clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 5, 2024
1 parent 2f0bb71 commit e067f6a
Show file tree
Hide file tree
Showing 27 changed files with 266 additions and 268 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Checks: >
-modernize-use-auto,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-performance-avoid-endl,
-performance-enum-size,
-performance-inefficient-string-concatenation,
-performance-no-automatic-move,
Expand Down
1 change: 0 additions & 1 deletion clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as
`readability-redundant-access-specifiers`<br/>
`concurrency-mt-unsafe`<br/>
`misc-use-anonymous-namespace`<br/>
`performance-avoid-endl`<br/>
`performance-noexcept-swap`<br/>
`bugprone-switch-missing-default-case`<br/>
`bugprone-empty-catch`<br/>
Expand Down
6 changes: 3 additions & 3 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace {
{
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
{
std::cout << outmsg << std::endl;
std::cout << outmsg << '\n';
}

void reportErr(const ErrorMessage &msg) override
Expand Down Expand Up @@ -175,7 +175,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
// TODO: this bypasses the template format and other settings
// If the include path is not found, warn user and remove the non-existing path from the list.
if (mSettings.severity.isEnabled(Severity::information))
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << '\n';
iter = mSettings.includePaths.erase(iter);
}
}
Expand Down Expand Up @@ -342,7 +342,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
XMLErrorMessagesLogger xmlLogger;
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName);
CppCheck::getErrorMessages(xmlLogger);
std::cout << ErrorMessage::getXMLFooter() << std::endl;
std::cout << ErrorMessage::getXMLFooter() << '\n';
}
return Result::Exit;
}
Expand Down
16 changes: 8 additions & 8 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace {

void printRaw(const std::string &message) override
{
std::cout << message << std::endl;
std::cout << message << '\n';
}
};

Expand Down Expand Up @@ -381,18 +381,18 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
void StdLogger::reportErr(const std::string &errmsg)
{
if (mErrorOutput)
*mErrorOutput << errmsg << std::endl;
*mErrorOutput << errmsg << '\n';
else {
std::cerr << ansiToOEM(errmsg, !mSettings.xml) << std::endl;
std::cerr << ansiToOEM(errmsg, !mSettings.xml) << '\n';
}
}

void StdLogger::reportOut(const std::string &outmsg, Color c)
{
if (c == Color::Reset)
std::cout << ansiToOEM(outmsg, true) << std::endl;
std::cout << ansiToOEM(outmsg, true) << '\n';
else
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << '\n';
}

// TODO: remove filename parameter?
Expand Down Expand Up @@ -499,11 +499,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
#else
FILE *p = popen(cmd.c_str(), "r");
#endif
//std::cout << "invoking command '" << cmd << "'" << std::endl;
//std::cout << "invoking command '" << cmd << "'" << '\n';
if (!p) {
// TODO: how to provide to caller?
//const int err = errno;
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
//std::cout << "popen() errno " << std::to_string(err) << '\n';
return -1;
}
char buffer[1024];
Expand All @@ -518,7 +518,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
if (res == -1) { // error occurred
// TODO: how to provide to caller?
//const int err = errno;
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
return res;
}
#if !defined(WIN32) && !defined(__MINGW32__)
Expand Down
24 changes: 12 additions & 12 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ namespace {
const ssize_t bytes_written = write(mWpipe, data, to_write);
if (bytes_written <= 0) {
const int err = errno;
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << '\n';
std::exit(EXIT_FAILURE);
}
// TODO: write until everything is written
if (bytes_written != to_write) {
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
std::exit(EXIT_FAILURE);
}
}
Expand Down Expand Up @@ -144,12 +144,12 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
return false;
}
if (bytes_read != bytes_to_read) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
std::exit(EXIT_FAILURE);
}

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

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

Expand All @@ -173,7 +173,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
bytes_read = read(rpipe, data_start, bytes_to_read);
if (bytes_read <= 0) {
const int err = errno;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << '\n';
std::exit(EXIT_FAILURE);
}
bytes_to_read -= bytes_read;
Expand All @@ -191,7 +191,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
try {
msg.deserialize(buf);
} catch (const InternalError& e) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << '\n';
std::exit(EXIT_FAILURE);
}

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

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

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

const pid_t pid = fork();
if (pid < 0) {
// Error
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << '\n';
std::exit(EXIT_FAILURE);
} else if (pid == 0) {
#if defined(__linux__)
Expand Down
2 changes: 1 addition & 1 deletion cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ unsigned int ThreadExecutor::check()
threadFutures.emplace_back(std::async(std::launch::async, &threadProc, &data));
}
catch (const std::system_error &e) {
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << std::endl;
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << '\n';
exit(EXIT_FAILURE);
}
}
Expand Down
4 changes: 2 additions & 2 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void ShowUsage()
);
(void)msgBox.exec();
#else
std::cout << helpMessage.toStdString() << std::endl;
std::cout << helpMessage.toStdString() << '\n';
#endif
}

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

std::cout << versionMessage << std::endl;
std::cout << versionMessage << '\n';
#endif
}
2 changes: 1 addition & 1 deletion lib/analyzerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::

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

Expand Down
2 changes: 1 addition & 1 deletion lib/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Check::Check(const std::string &aname)

void Check::writeToErrorList(const ErrorMessage &errmsg)
{
std::cout << errmsg.toXML() << std::endl;
std::cout << errmsg.toXML() << '\n';
}


Expand Down
44 changes: 22 additions & 22 deletions lib/checkersreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
{
std::ostringstream fout;

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

fout << std::endl << std::endl;
fout << "Open source checkers" << std::endl;
fout << "--------------------" << std::endl;
fout << '\n' << '\n';
fout << "Open source checkers" << '\n';
fout << "--------------------" << '\n';

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

const bool cppcheckPremium = isCppcheckPremium(mSettings);
Expand All @@ -142,11 +142,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
const std::set<std::string>& activeCheckers,
const std::map<std::string, std::string>& premiumCheckers,
const std::string& substring) {
fout << std::endl << std::endl;
fout << title << std::endl;
fout << std::string(title.size(), '-') << std::endl;
fout << '\n' << '\n';
fout << title << '\n';
fout << std::string(title.size(), '-') << '\n';
if (!cppcheckPremium) {
fout << "Not available, Cppcheck Premium is not used" << std::endl;
fout << "Not available, Cppcheck Premium is not used" << '\n';
return;
}
int maxCheckerSize = 0;
Expand Down Expand Up @@ -174,7 +174,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
req = "premium";
if (!active)
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
fout << std::endl;
fout << '\n';
}
};

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

if (misra == 0) {
fout << std::endl << std::endl;
fout << "Misra C" << std::endl;
fout << "-------" << std::endl;
fout << "Misra is not enabled" << std::endl;
fout << '\n' << '\n';
fout << "Misra C" << '\n';
fout << "-------" << '\n';
fout << "Misra is not enabled" << '\n';
} else {
fout << std::endl << std::endl;
fout << "Misra C " << misra << std::endl;
fout << "------------" << std::endl;
fout << '\n' << '\n';
fout << "Misra C " << misra << '\n';
fout << "------------" << '\n';
for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b);
const std::string severity = getMisraRuleSeverity(rule);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static bool isVarTokComparison(const Token * tok, const Token ** vartok,

void VarInfo::print()
{
std::cout << "size=" << alloctype.size() << std::endl;
std::cout << "size=" << alloctype.size() << '\n';
for (std::map<int, AllocInfo>::const_iterator it = alloctype.cbegin(); it != alloctype.cend(); ++it) {
std::string strusage;
const auto use = possibleUsage.find(it->first);
Expand Down Expand Up @@ -141,7 +141,7 @@ void VarInfo::print()
<< "conditionalAlloc=" << (conditionalAlloc.find(it->first) != conditionalAlloc.end() ? "yes" : "no") << " "
<< "referenced=" << (referenced.find(it->first) != referenced.end() ? "yes" : "no") << " "
<< "reallocedFrom=" << it->second.reallocedFromType
<< std::endl;
<< '\n';
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ void clangimport::AstNode::dumpAst(int num, int indent) const
std::cout << std::string(indent, ' ') << nodeType;
for (const auto& tok: mExtTokens)
std::cout << " " << tok;
std::cout << std::endl;
std::cout << '\n';
for (int c = 0; c < children.size(); ++c) {
if (children[c])
children[c]->dumpAst(c, indent + 2);
else
std::cout << std::string(indent + 2, ' ') << "<<<<NULL>>>>>" << std::endl;
std::cout << std::string(indent + 2, ' ') << "<<<<NULL>>>>>" << '\n';
}
}

Expand Down
Loading

0 comments on commit e067f6a

Please sign in to comment.