diff --git a/.clang-tidy b/.clang-tidy index d5054062dac..80cde91911f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -50,7 +50,6 @@ Checks: > -modernize-use-auto, -modernize-use-nodiscard, -modernize-use-trailing-return-type, - -performance-avoid-endl, -performance-inefficient-string-concatenation, -performance-no-automatic-move, -performance-noexcept-swap, diff --git a/clang-tidy.md b/clang-tidy.md index dce24786dcb..82adf24d3a8 100644 --- a/clang-tidy.md +++ b/clang-tidy.md @@ -121,7 +121,6 @@ We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as `bugprone-signed-char-misuse`
`concurrency-mt-unsafe`
`misc-use-anonymous-namespace`
-`performance-avoid-endl`
`performance-noexcept-swap`
`bugprone-switch-missing-default-case`
`bugprone-empty-catch`
diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 5da5b898e4c..e0d16eac6bf 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -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 @@ -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); } } @@ -345,7 +345,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; } diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 31122583e24..93e250dd15f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -88,7 +88,7 @@ namespace { void printRaw(const std::string &message) override { - std::cout << message << std::endl; + std::cout << message << '\n'; } }; @@ -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? @@ -499,11 +499,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector 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]; @@ -518,7 +518,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector 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__) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index eaba040ae8f..d61e428a7a9 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -96,12 +96,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); } } @@ -145,12 +145,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); } @@ -159,11 +159,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); } @@ -174,7 +174,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; @@ -192,7 +192,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); } @@ -249,25 +249,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__) diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 5d4d3a760e6..62125419f52 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -188,7 +188,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); } } diff --git a/gui/main.cpp b/gui/main.cpp index 91bc9e7a084..48fa6ae645d 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -124,7 +124,7 @@ static void ShowUsage() ); (void)msgBox.exec(); #else - std::cout << helpMessage.toStdString() << std::endl; + std::cout << helpMessage.toStdString() << '\n'; #endif } @@ -141,6 +141,6 @@ static void ShowVersion() if (*extraVersion != 0) versionMessage += std::string(" (") + extraVersion + ")"; - std::cout << versionMessage << std::endl; + std::cout << versionMessage << '\n'; #endif } diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 9d5b914c2bd..8788523d979 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -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(fs.filename()) << std::endl; + fout << afile << ".a" << (++fileCount[afile]) << ":" << fs.cfg << ":" << Path::simplifyPath(fs.filename()) << '\n'; } } diff --git a/lib/check.cpp b/lib/check.cpp index c5e6368f1fc..e8f90363193 100644 --- a/lib/check.cpp +++ b/lib/check.cpp @@ -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'; } diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index f6b7c2e8c0b..4657a35e916 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -137,19 +137,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) { @@ -164,7 +164,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); @@ -175,11 +175,11 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const const std::set& activeCheckers, const std::map& 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; @@ -215,7 +215,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const req = "require:" + req; if (!active) fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << req; - fout << std::endl; + fout << '\n'; } }; @@ -233,14 +233,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 bool active = isMisraRuleActive(mActiveCheckers, rule); diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 984b297a8b0..e3b0b03a034 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -493,12 +493,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, ' ') << "<<<>>>>" << std::endl; + std::cout << std::string(indent + 2, ' ') << "<<<>>>>" << '\n'; } } diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 45fbb89678d..38c834d8365 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -451,7 +451,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) const std::string redirect2 = analyzerInfo.empty() ? std::string("2>&1") : ("2> " + clangStderr); if (!mSettings.buildDir.empty()) { std::ofstream fout(clangcmd); - fout << exe << " " << args2 << " " << redirect2 << std::endl; + fout << exe << " " << args2 << " " << redirect2 << '\n'; } else if (mSettings.verbose && !mSettings.quiet) { mErrorLogger.reportOut(exe + " " + args2); } @@ -460,13 +460,13 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) const int exitcode = mExecuteCommand(exe,split(args2),redirect2,output2); if (exitcode != EXIT_SUCCESS) { // TODO: report as proper error - std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (exitcode: " << exitcode << " / output: " << output2 << ")" << std::endl; + std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (exitcode: " << exitcode << " / output: " << output2 << ")" << '\n'; return 0; // TODO: report as failure? } if (output2.find("TranslationUnitDecl") == std::string::npos) { // TODO: report as proper error - std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no TranslationUnitDecl in output)" << std::endl; + std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no TranslationUnitDecl in output)" << '\n'; return 0; // TODO: report as failure? } @@ -490,7 +490,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file) if (!mSettings.buildDir.empty()) { std::ofstream fout(clangAst); - fout << output2 << std::endl; + fout << output2 << '\n'; } try { @@ -891,14 +891,14 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string // dump xml if --dump if ((mSettings.dump || !mSettings.addons.empty()) && fdump.is_open()) { - fdump << "" << std::endl; - fdump << " " << std::endl; - fdump << " " << std::endl; - fdump << " " << std::endl; - fdump << " " << std::endl; + fdump << "" << '\n'; + fdump << " " << '\n'; + fdump << " " << '\n'; + fdump << " " << '\n'; + fdump << " " << '\n'; preprocessor.dump(fdump); tokenizer.dump(fdump); - fdump << "" << std::endl; + fdump << "" << '\n'; } // Need to call this even if the hash will skip this configuration @@ -970,7 +970,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string // dumped all configs, close root element now if (fdump.is_open()) { - fdump << "" << std::endl; + fdump << "" << '\n'; fdump.close(); } @@ -1401,7 +1401,7 @@ void CppCheck::executeAddons(const std::vector& files, const std::s filesDeleter.addFile(fileList); std::ofstream fout(fileList); for (const std::string& f: files) - fout << f << std::endl; + fout << f << '\n'; } // ensure all addons have already been resolved - TODO: remove when settings are const after creation @@ -1698,7 +1698,7 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings) const std::string args = "-quiet -checks=*,-clang-analyzer-*,-llvm* \"" + fileSettings.filename() + "\" -- " + allIncludes + allDefines; std::string output; if (const int exitcode = mExecuteCommand(exe, split(args), emptyString, output)) { - std::cerr << "Failed to execute '" << exe << "' (exitcode: " << std::to_string(exitcode) << ")" << std::endl; + std::cerr << "Failed to execute '" << exe << "' (exitcode: " << std::to_string(exitcode) << ")" << '\n'; return; } diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 336e25744c8..287d49bf9d9 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -1369,7 +1369,7 @@ void ImportProject::setRelativePaths(const std::string &filename) void ImportProject::printError(const std::string &message) { - std::cout << "cppcheck: error: " << message << std::endl; + std::cout << "cppcheck: error: " << message << '\n'; } bool ImportProject::sourceFileExists(const std::string &file) diff --git a/lib/platform.cpp b/lib/platform.cpp index f54b9110afe..208fea307ac 100644 --- a/lib/platform.cpp +++ b/lib/platform.cpp @@ -174,7 +174,7 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st bool found = false; for (const std::string& path : paths) { if (verbose) - std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << std::endl; + std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << '\n'; if (loadFromFile(path.c_str(), platformstr, verbose)) { found = true; break; @@ -220,12 +220,12 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b std::cout << "try to load platform file '" << f << "' ... "; if (doc.LoadFile(f.c_str()) == tinyxml2::XML_SUCCESS) { if (verbose) - std::cout << "Success" << std::endl; + std::cout << "Success" << '\n'; success = true; break; } if (verbose) - std::cout << doc.ErrorStr() << std::endl; + std::cout << doc.ErrorStr() << '\n'; } if (!success) return false; diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 58fb06ff0bf..ebdc00c78bb 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -931,7 +931,7 @@ void Preprocessor::dump(std::ostream &out) const // Create a xml dump. if (!mMacroUsage.empty()) { - out << " " << std::endl; + out << " " << '\n'; for (const simplecpp::MacroUsage ¯oUsage: mMacroUsage) { out << " " << std::endl; + << "/>" << '\n'; } - out << " " << std::endl; + out << " " << '\n'; } if (!mIfCond.empty()) { - out << " " << std::endl; + out << " " << '\n'; for (const simplecpp::IfCond &ifCond: mIfCond) { out << " " << std::endl; + << "/>" << '\n'; } - out << " " << std::endl; + out << " " << '\n'; } } diff --git a/lib/summaries.cpp b/lib/summaries.cpp index a893b13a0aa..c0d253e431d 100644 --- a/lib/summaries.cpp +++ b/lib/summaries.cpp @@ -78,7 +78,7 @@ std::string Summaries::create(const Tokenizer &tokenizer, const std::string &cfg ostr << " call:[" << join(calledFunctions) << "]"; if (!noreturn.empty()) ostr << " noreturn:[" << join(noreturn) << "]"; - ostr << std::endl; + ostr << '\n'; } if (!settings.buildDir.empty()) { diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 71481f324a5..c1cac628a3d 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -446,7 +446,7 @@ bool SuppressionList::isSuppressed(const ::ErrorMessage &errmsg, const std::set< void SuppressionList::dump(std::ostream & out) const { - out << " " << std::endl; + out << " " << '\n'; for (const Suppression &suppression : mSuppressions) { out << " " << std::endl; + out << " />" << '\n'; } - out << " " << std::endl; + out << " " << '\n'; } std::list SuppressionList::getUnmatchedLocalSuppressions(const FileWithDetails &file, const bool unusedFunctionChecking) const diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 31e54535512..76e17f9c83e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3864,12 +3864,12 @@ static std::string tokenType(const Token * tok) void SymbolDatabase::printVariable(const Variable *var, const char *indent) const { - std::cout << indent << "mNameToken: " << tokenToString(var->nameToken(), mTokenizer) << std::endl; + std::cout << indent << "mNameToken: " << tokenToString(var->nameToken(), mTokenizer) << '\n'; if (var->nameToken()) { - std::cout << indent << " declarationId: " << var->declarationId() << std::endl; + std::cout << indent << " declarationId: " << var->declarationId() << '\n'; } - std::cout << indent << "mTypeStartToken: " << tokenToString(var->typeStartToken(), mTokenizer) << std::endl; - std::cout << indent << "mTypeEndToken: " << tokenToString(var->typeEndToken(), mTokenizer) << std::endl; + std::cout << indent << "mTypeStartToken: " << tokenToString(var->typeStartToken(), mTokenizer) << '\n'; + std::cout << indent << "mTypeEndToken: " << tokenToString(var->typeEndToken(), mTokenizer) << '\n'; if (var->typeStartToken()) { const Token * autoTok = nullptr; @@ -3879,49 +3879,49 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons if (tok->str() == "auto") autoTok = tok; } - std::cout << std::endl; + std::cout << '\n'; if (autoTok) { const ValueType * valueType = autoTok->valueType(); - std::cout << indent << " auto valueType: " << valueType << std::endl; + std::cout << indent << " auto valueType: " << valueType << '\n'; if (var->typeStartToken()->valueType()) { - std::cout << indent << " " << valueType->str() << std::endl; + std::cout << indent << " " << valueType->str() << '\n'; } } } else if (var->valueType()) { - std::cout << indent << " " << var->valueType()->str() << std::endl; - } - std::cout << indent << "mIndex: " << var->index() << std::endl; - std::cout << indent << "mAccess: " << accessControlToString(var->accessControl()) << std::endl; - std::cout << indent << "mFlags: " << std::endl; - std::cout << indent << " isMutable: " << var->isMutable() << std::endl; - std::cout << indent << " isStatic: " << var->isStatic() << std::endl; - std::cout << indent << " isExtern: " << var->isExtern() << std::endl; - std::cout << indent << " isLocal: " << var->isLocal() << std::endl; - std::cout << indent << " isConst: " << var->isConst() << std::endl; - std::cout << indent << " isClass: " << var->isClass() << std::endl; - std::cout << indent << " isArray: " << var->isArray() << std::endl; - std::cout << indent << " isPointer: " << var->isPointer() << std::endl; - std::cout << indent << " isReference: " << var->isReference() << std::endl; - std::cout << indent << " isRValueRef: " << var->isRValueReference() << std::endl; - std::cout << indent << " hasDefault: " << var->hasDefault() << std::endl; - std::cout << indent << " isStlType: " << var->isStlType() << std::endl; + std::cout << indent << " " << var->valueType()->str() << '\n'; + } + std::cout << indent << "mIndex: " << var->index() << '\n'; + std::cout << indent << "mAccess: " << accessControlToString(var->accessControl()) << '\n'; + std::cout << indent << "mFlags: " << '\n'; + std::cout << indent << " isMutable: " << var->isMutable() << '\n'; + std::cout << indent << " isStatic: " << var->isStatic() << '\n'; + std::cout << indent << " isExtern: " << var->isExtern() << '\n'; + std::cout << indent << " isLocal: " << var->isLocal() << '\n'; + std::cout << indent << " isConst: " << var->isConst() << '\n'; + std::cout << indent << " isClass: " << var->isClass() << '\n'; + std::cout << indent << " isArray: " << var->isArray() << '\n'; + std::cout << indent << " isPointer: " << var->isPointer() << '\n'; + std::cout << indent << " isReference: " << var->isReference() << '\n'; + std::cout << indent << " isRValueRef: " << var->isRValueReference() << '\n'; + std::cout << indent << " hasDefault: " << var->hasDefault() << '\n'; + std::cout << indent << " isStlType: " << var->isStlType() << '\n'; std::cout << indent << "mType: "; if (var->type()) { std::cout << var->type()->type() << " " << var->type()->name(); std::cout << " " << mTokenizer.list.fileLine(var->type()->classDef); - std::cout << " " << var->type() << std::endl; + std::cout << " " << var->type() << '\n'; } else - std::cout << "none" << std::endl; + std::cout << "none" << '\n'; if (var->nameToken()) { const ValueType * valueType = var->nameToken()->valueType(); - std::cout << indent << "valueType: " << valueType << std::endl; + std::cout << indent << "valueType: " << valueType << '\n'; if (valueType) { - std::cout << indent << " " << valueType->str() << std::endl; + std::cout << indent << " " << valueType->str() << '\n'; } } - std::cout << indent << "mScope: " << scopeToString(var->scope(), mTokenizer) << std::endl; + std::cout << indent << "mScope: " << scopeToString(var->scope(), mTokenizer) << '\n'; std::cout << indent << "mDimensions:"; for (std::size_t i = 0; i < var->dimensions().size(); i++) { @@ -3929,7 +3929,7 @@ void SymbolDatabase::printVariable(const Variable *var, const char *indent) cons if (!var->dimensions()[i].known) std::cout << "?"; } - std::cout << std::endl; + std::cout << '\n'; } void SymbolDatabase::printOut(const char *title) const @@ -3939,40 +3939,40 @@ void SymbolDatabase::printOut(const char *title) const std::cout << "\n### " << title << " ###\n"; for (std::list::const_iterator scope = scopeList.cbegin(); scope != scopeList.cend(); ++scope) { - std::cout << "Scope: " << &*scope << " " << scope->type << std::endl; - std::cout << " className: " << scope->className << std::endl; - std::cout << " classDef: " << tokenToString(scope->classDef, mTokenizer) << std::endl; - std::cout << " bodyStart: " << tokenToString(scope->bodyStart, mTokenizer) << std::endl; - std::cout << " bodyEnd: " << tokenToString(scope->bodyEnd, mTokenizer) << std::endl; + std::cout << "Scope: " << &*scope << " " << scope->type << '\n'; + std::cout << " className: " << scope->className << '\n'; + std::cout << " classDef: " << tokenToString(scope->classDef, mTokenizer) << '\n'; + std::cout << " bodyStart: " << tokenToString(scope->bodyStart, mTokenizer) << '\n'; + std::cout << " bodyEnd: " << tokenToString(scope->bodyEnd, mTokenizer) << '\n'; // find the function body if not implemented inline for (auto func = scope->functionList.cbegin(); func != scope->functionList.cend(); ++func) { - std::cout << " Function: " << &*func << std::endl; - std::cout << " name: " << tokenToString(func->tokenDef, mTokenizer) << std::endl; - std::cout << " type: " << functionTypeToString(func->type) << std::endl; - std::cout << " access: " << accessControlToString(func->access) << std::endl; - std::cout << " hasBody: " << func->hasBody() << std::endl; - std::cout << " isInline: " << func->isInline() << std::endl; - std::cout << " isConst: " << func->isConst() << std::endl; - std::cout << " hasVirtualSpecifier: " << func->hasVirtualSpecifier() << std::endl; - std::cout << " isPure: " << func->isPure() << std::endl; - std::cout << " isStatic: " << func->isStatic() << std::endl; - std::cout << " isStaticLocal: " << func->isStaticLocal() << std::endl; - std::cout << " isExtern: " << func->isExtern() << std::endl; - std::cout << " isFriend: " << func->isFriend() << std::endl; - std::cout << " isExplicit: " << func->isExplicit() << std::endl; - std::cout << " isDefault: " << func->isDefault() << std::endl; - std::cout << " isDelete: " << func->isDelete() << std::endl; - std::cout << " hasOverrideSpecifier: " << func->hasOverrideSpecifier() << std::endl; - std::cout << " hasFinalSpecifier: " << func->hasFinalSpecifier() << std::endl; - std::cout << " isNoExcept: " << func->isNoExcept() << std::endl; - std::cout << " isThrow: " << func->isThrow() << std::endl; - std::cout << " isOperator: " << func->isOperator() << std::endl; - std::cout << " hasLvalRefQual: " << func->hasLvalRefQualifier() << std::endl; - std::cout << " hasRvalRefQual: " << func->hasRvalRefQualifier() << std::endl; - std::cout << " isVariadic: " << func->isVariadic() << std::endl; - std::cout << " isVolatile: " << func->isVolatile() << std::endl; - std::cout << " hasTrailingReturnType: " << func->hasTrailingReturnType() << std::endl; + std::cout << " Function: " << &*func << '\n'; + std::cout << " name: " << tokenToString(func->tokenDef, mTokenizer) << '\n'; + std::cout << " type: " << functionTypeToString(func->type) << '\n'; + std::cout << " access: " << accessControlToString(func->access) << '\n'; + std::cout << " hasBody: " << func->hasBody() << '\n'; + std::cout << " isInline: " << func->isInline() << '\n'; + std::cout << " isConst: " << func->isConst() << '\n'; + std::cout << " hasVirtualSpecifier: " << func->hasVirtualSpecifier() << '\n'; + std::cout << " isPure: " << func->isPure() << '\n'; + std::cout << " isStatic: " << func->isStatic() << '\n'; + std::cout << " isStaticLocal: " << func->isStaticLocal() << '\n'; + std::cout << " isExtern: " << func->isExtern() << '\n'; + std::cout << " isFriend: " << func->isFriend() << '\n'; + std::cout << " isExplicit: " << func->isExplicit() << '\n'; + std::cout << " isDefault: " << func->isDefault() << '\n'; + std::cout << " isDelete: " << func->isDelete() << '\n'; + std::cout << " hasOverrideSpecifier: " << func->hasOverrideSpecifier() << '\n'; + std::cout << " hasFinalSpecifier: " << func->hasFinalSpecifier() << '\n'; + std::cout << " isNoExcept: " << func->isNoExcept() << '\n'; + std::cout << " isThrow: " << func->isThrow() << '\n'; + std::cout << " isOperator: " << func->isOperator() << '\n'; + std::cout << " hasLvalRefQual: " << func->hasLvalRefQualifier() << '\n'; + std::cout << " hasRvalRefQual: " << func->hasRvalRefQualifier() << '\n'; + std::cout << " isVariadic: " << func->isVariadic() << '\n'; + std::cout << " isVolatile: " << func->isVolatile() << '\n'; + std::cout << " hasTrailingReturnType: " << func->hasTrailingReturnType() << '\n'; std::cout << " attributes:"; if (func->isAttributeConst()) std::cout << " const "; @@ -3988,41 +3988,41 @@ void SymbolDatabase::printOut(const char *title) const std::cout << " destructor "; if (func->isAttributeNodiscard()) std::cout << " nodiscard "; - std::cout << std::endl; - std::cout << " noexceptArg: " << (func->noexceptArg ? func->noexceptArg->str() : "none") << std::endl; - std::cout << " throwArg: " << (func->throwArg ? func->throwArg->str() : "none") << std::endl; - std::cout << " tokenDef: " << tokenToString(func->tokenDef, mTokenizer) << std::endl; - std::cout << " argDef: " << tokenToString(func->argDef, mTokenizer) << std::endl; + std::cout << '\n'; + std::cout << " noexceptArg: " << (func->noexceptArg ? func->noexceptArg->str() : "none") << '\n'; + std::cout << " throwArg: " << (func->throwArg ? func->throwArg->str() : "none") << '\n'; + std::cout << " tokenDef: " << tokenToString(func->tokenDef, mTokenizer) << '\n'; + std::cout << " argDef: " << tokenToString(func->argDef, mTokenizer) << '\n'; if (!func->isConstructor() && !func->isDestructor()) - std::cout << " retDef: " << tokenToString(func->retDef, mTokenizer) << std::endl; + std::cout << " retDef: " << tokenToString(func->retDef, mTokenizer) << '\n'; if (func->retDef) { std::cout << " "; for (const Token * tok = func->retDef; tok && tok != func->tokenDef && !Token::Match(tok, "{|;|override|final"); tok = tok->next()) std::cout << " " << tokenType(tok); - std::cout << std::endl; + std::cout << '\n'; } - std::cout << " retType: " << func->retType << std::endl; + std::cout << " retType: " << func->retType << '\n'; if (const ValueType* valueType = func->tokenDef->next()->valueType()) { - std::cout << " valueType: " << valueType << std::endl; - std::cout << " " << valueType->str() << std::endl; + std::cout << " valueType: " << valueType << '\n'; + std::cout << " " << valueType->str() << '\n'; } if (func->hasBody()) { - std::cout << " token: " << tokenToString(func->token, mTokenizer) << std::endl; - std::cout << " arg: " << tokenToString(func->arg, mTokenizer) << std::endl; + std::cout << " token: " << tokenToString(func->token, mTokenizer) << '\n'; + std::cout << " arg: " << tokenToString(func->arg, mTokenizer) << '\n'; } - std::cout << " nestedIn: " << scopeToString(func->nestedIn, mTokenizer) << std::endl; - std::cout << " functionScope: " << scopeToString(func->functionScope, mTokenizer) << std::endl; + std::cout << " nestedIn: " << scopeToString(func->nestedIn, mTokenizer) << '\n'; + std::cout << " functionScope: " << scopeToString(func->functionScope, mTokenizer) << '\n'; for (auto var = func->argumentList.cbegin(); var != func->argumentList.cend(); ++var) { - std::cout << " Variable: " << &*var << std::endl; + std::cout << " Variable: " << &*var << '\n'; printVariable(&*var, " "); } } for (auto var = scope->varlist.cbegin(); var != scope->varlist.cend(); ++var) { - std::cout << " Variable: " << &*var << std::endl; + std::cout << " Variable: " << &*var << '\n'; printVariable(&*var, " "); } @@ -4032,8 +4032,8 @@ void SymbolDatabase::printOut(const char *title) const std::cout << scope->enumType->stringify(false, true, false); } else std::cout << "int"; - std::cout << std::endl; - std::cout << " enumClass: " << scope->enumClass << std::endl; + std::cout << '\n'; + std::cout << " enumClass: " << scope->enumClass << '\n'; for (const Enumerator &enumerator : scope->enumeratorList) { std::cout << " Enumerator: " << enumerator.name->str() << " = "; if (enumerator.value_known) @@ -4051,7 +4051,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << "]"; } - std::cout << std::endl; + std::cout << '\n'; } } @@ -4060,9 +4060,9 @@ void SymbolDatabase::printOut(const char *title) const std::cout << " " << scope->nestedIn->type << " " << scope->nestedIn->className; } - std::cout << std::endl; + std::cout << '\n'; - std::cout << " definedType: " << scope->definedType << std::endl; + std::cout << " definedType: " << scope->definedType << '\n'; std::cout << " nestedList[" << scope->nestedList.size() << "] = ("; @@ -4073,7 +4073,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << ","; } - std::cout << " )" << std::endl; + std::cout << " )" << '\n'; for (auto use = scope->usingList.cbegin(); use != scope->usingList.cend(); ++use) { std::cout << " using: " << use->scope << " " << use->start->strAt(2); @@ -4082,32 +4082,32 @@ void SymbolDatabase::printOut(const char *title) const std::cout << "::" << tok1->strAt(1); tok1 = tok1->tokAt(2); } - std::cout << " " << mTokenizer.list.fileLine(use->start) << std::endl; + std::cout << " " << mTokenizer.list.fileLine(use->start) << '\n'; } - std::cout << " functionOf: " << scopeToString(scope->functionOf, mTokenizer) << std::endl; + std::cout << " functionOf: " << scopeToString(scope->functionOf, mTokenizer) << '\n'; std::cout << " function: " << scope->function; if (scope->function) std::cout << " " << scope->function->name(); - std::cout << std::endl; + std::cout << '\n'; } for (std::list::const_iterator type = typeList.cbegin(); type != typeList.cend(); ++type) { - std::cout << "Type: " << &(*type) << std::endl; - std::cout << " name: " << type->name() << std::endl; - std::cout << " classDef: " << tokenToString(type->classDef, mTokenizer) << std::endl; - std::cout << " classScope: " << type->classScope << std::endl; + std::cout << "Type: " << &(*type) << '\n'; + std::cout << " name: " << type->name() << '\n'; + std::cout << " classDef: " << tokenToString(type->classDef, mTokenizer) << '\n'; + std::cout << " classScope: " << type->classScope << '\n'; std::cout << " enclosingScope: " << type->enclosingScope; if (type->enclosingScope) { std::cout << " " << type->enclosingScope->type << " " << type->enclosingScope->className; } - std::cout << std::endl; + std::cout << '\n'; std::cout << " needInitialization: " << (type->needInitialization == Type::NeedInitialization::Unknown ? "Unknown" : type->needInitialization == Type::NeedInitialization::True ? "True" : type->needInitialization == Type::NeedInitialization::False ? "False" : - "Invalid") << std::endl; + "Invalid") << '\n'; std::cout << " derivedFrom[" << type->derivedFrom.size() << "] = ("; std::size_t count = type->derivedFrom.size(); @@ -4130,7 +4130,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << ","; } - std::cout << " )" << std::endl; + std::cout << " )" << '\n'; std::cout << " friendList[" << type->friendList.size() << "] = ("; for (size_t i = 0; i < type->friendList.size(); i++) { @@ -4146,7 +4146,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << ','; } - std::cout << " )" << std::endl; + std::cout << " )" << '\n'; } for (std::size_t i = 1; i < mVariableList.size(); i++) { @@ -4155,7 +4155,7 @@ void SymbolDatabase::printOut(const char *title) const std::cout << " " << mVariableList[i]->name() << " " << mTokenizer.list.fileLine(mVariableList[i]->nameToken()); } - std::cout << std::endl; + std::cout << '\n'; } std::cout << std::resetiosflags(std::ios::boolalpha); } diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5933b279481..6befec00eec 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -3543,22 +3543,22 @@ void TemplateSimplifier::printOut(const TokenAndName &tokenAndName, const std::s std::cout << "\"" << tokenAndName.token()->str() << "\" " << mTokenList.fileLine(tokenAndName.token()); else std::cout << "nullptr"; - std::cout << std::endl; - std::cout << indent << "scope: \"" << tokenAndName.scope() << "\"" << std::endl; - std::cout << indent << "name: \"" << tokenAndName.name() << "\"" << std::endl; - std::cout << indent << "fullName: \"" << tokenAndName.fullName() << "\"" << std::endl; + std::cout << '\n'; + std::cout << indent << "scope: \"" << tokenAndName.scope() << "\"" << '\n'; + std::cout << indent << "name: \"" << tokenAndName.name() << "\"" << '\n'; + std::cout << indent << "fullName: \"" << tokenAndName.fullName() << "\"" << '\n'; std::cout << indent << "nameToken: "; if (tokenAndName.nameToken()) std::cout << "\"" << tokenAndName.nameToken()->str() << "\" " << mTokenList.fileLine(tokenAndName.nameToken()); else std::cout << "nullptr"; - std::cout << std::endl; + std::cout << '\n'; std::cout << indent << "paramEnd: "; if (tokenAndName.paramEnd()) std::cout << "\"" << tokenAndName.paramEnd()->str() << "\" " << mTokenList.fileLine(tokenAndName.paramEnd()); else std::cout << "nullptr"; - std::cout << std::endl; + std::cout << '\n'; std::cout << indent << "flags: "; if (tokenAndName.isClass()) std::cout << " isClass"; @@ -3578,7 +3578,7 @@ void TemplateSimplifier::printOut(const TokenAndName &tokenAndName, const std::s std::cout << " isVariadic"; if (tokenAndName.isFriend()) std::cout << " isFriend"; - std::cout << std::endl; + std::cout << '\n'; if (tokenAndName.token() && !tokenAndName.paramEnd() && tokenAndName.token()->strAt(1) == "<") { const Token *end = tokenAndName.token()->next()->findClosingBracket(); if (end) { @@ -3594,38 +3594,38 @@ void TemplateSimplifier::printOut(const TokenAndName &tokenAndName, const std::s std::cout << start->str(); start = start->next(); } - std::cout << end->str() << std::endl; + std::cout << end->str() << '\n'; } } else if (tokenAndName.isAlias() && tokenAndName.paramEnd()) { if (tokenAndName.aliasStartToken()) { std::cout << indent << "aliasStartToken: \"" << tokenAndName.aliasStartToken()->str() << "\" " - << mTokenList.fileLine(tokenAndName.aliasStartToken()) << std::endl; + << mTokenList.fileLine(tokenAndName.aliasStartToken()) << '\n'; } if (tokenAndName.aliasEndToken()) { std::cout << indent << "aliasEndToken: \"" << tokenAndName.aliasEndToken()->str() << "\" " - << mTokenList.fileLine(tokenAndName.aliasEndToken()) << std::endl; + << mTokenList.fileLine(tokenAndName.aliasEndToken()) << '\n'; } } } void TemplateSimplifier::printOut(const std::string & text) const { - std::cout << std::endl; - std::cout << text << std::endl; - std::cout << std::endl; - std::cout << "mTemplateDeclarations: " << mTemplateDeclarations.size() << std::endl; + std::cout << '\n'; + std::cout << text << '\n'; + std::cout << '\n'; + std::cout << "mTemplateDeclarations: " << mTemplateDeclarations.size() << '\n'; int count = 0; for (const auto & decl : mTemplateDeclarations) { - std::cout << "mTemplateDeclarations[" << count++ << "]:" << std::endl; + std::cout << "mTemplateDeclarations[" << count++ << "]:" << '\n'; printOut(decl); } - std::cout << "mTemplateForwardDeclarations: " << mTemplateForwardDeclarations.size() << std::endl; + std::cout << "mTemplateForwardDeclarations: " << mTemplateForwardDeclarations.size() << '\n'; count = 0; for (const auto & decl : mTemplateForwardDeclarations) { - std::cout << "mTemplateForwardDeclarations[" << count++ << "]:" << std::endl; + std::cout << "mTemplateForwardDeclarations[" << count++ << "]:" << '\n'; printOut(decl); } - std::cout << "mTemplateForwardDeclarationsMap: " << mTemplateForwardDeclarationsMap.size() << std::endl; + std::cout << "mTemplateForwardDeclarationsMap: " << mTemplateForwardDeclarationsMap.size() << '\n'; unsigned int mapIndex = 0; for (const auto & mapItem : mTemplateForwardDeclarationsMap) { unsigned int declIndex = 0; @@ -3634,9 +3634,9 @@ void TemplateSimplifier::printOut(const std::string & text) const unsigned int forwardIndex = 0; for (const auto & forwardDecl : mTemplateForwardDeclarations) { if (mapItem.second == forwardDecl.token()) { - std::cout << "mTemplateForwardDeclarationsMap[" << mapIndex << "]:" << std::endl; + std::cout << "mTemplateForwardDeclarationsMap[" << mapIndex << "]:" << '\n'; std::cout << " mTemplateDeclarations[" << declIndex - << "] => mTemplateForwardDeclarations[" << forwardIndex << "]" << std::endl; + << "] => mTemplateForwardDeclarations[" << forwardIndex << "]" << '\n'; break; } forwardIndex++; @@ -3647,7 +3647,7 @@ void TemplateSimplifier::printOut(const std::string & text) const } mapIndex++; } - std::cout << "mTemplateSpecializationMap: " << mTemplateSpecializationMap.size() << std::endl; + std::cout << "mTemplateSpecializationMap: " << mTemplateSpecializationMap.size() << '\n'; for (const auto & mapItem : mTemplateSpecializationMap) { unsigned int decl1Index = 0; for (const auto & decl1 : mTemplateDeclarations) { @@ -3656,9 +3656,9 @@ void TemplateSimplifier::printOut(const std::string & text) const unsigned int decl2Index = 0; for (const auto & decl2 : mTemplateDeclarations) { if (mapItem.second == decl2.token()) { - std::cout << "mTemplateSpecializationMap[" << mapIndex << "]:" << std::endl; + std::cout << "mTemplateSpecializationMap[" << mapIndex << "]:" << '\n'; std::cout << " mTemplateDeclarations[" << decl1Index - << "] => mTemplateDeclarations[" << decl2Index << "]" << std::endl; + << "] => mTemplateDeclarations[" << decl2Index << "]" << '\n'; found = true; break; } @@ -3668,9 +3668,9 @@ void TemplateSimplifier::printOut(const std::string & text) const decl2Index = 0; for (const auto & decl2 : mTemplateForwardDeclarations) { if (mapItem.second == decl2.token()) { - std::cout << "mTemplateSpecializationMap[" << mapIndex << "]:" << std::endl; + std::cout << "mTemplateSpecializationMap[" << mapIndex << "]:" << '\n'; std::cout << " mTemplateDeclarations[" << decl1Index - << "] => mTemplateForwardDeclarations[" << decl2Index << "]" << std::endl; + << "] => mTemplateForwardDeclarations[" << decl2Index << "]" << '\n'; break; } decl2Index++; @@ -3682,7 +3682,7 @@ void TemplateSimplifier::printOut(const std::string & text) const } mapIndex++; } - std::cout << "mTemplatePartialSpecializationMap: " << mTemplatePartialSpecializationMap.size() << std::endl; + std::cout << "mTemplatePartialSpecializationMap: " << mTemplatePartialSpecializationMap.size() << '\n'; for (const auto & mapItem : mTemplatePartialSpecializationMap) { unsigned int decl1Index = 0; for (const auto & decl1 : mTemplateDeclarations) { @@ -3691,9 +3691,9 @@ void TemplateSimplifier::printOut(const std::string & text) const unsigned int decl2Index = 0; for (const auto & decl2 : mTemplateDeclarations) { if (mapItem.second == decl2.token()) { - std::cout << "mTemplatePartialSpecializationMap[" << mapIndex << "]:" << std::endl; + std::cout << "mTemplatePartialSpecializationMap[" << mapIndex << "]:" << '\n'; std::cout << " mTemplateDeclarations[" << decl1Index - << "] => mTemplateDeclarations[" << decl2Index << "]" << std::endl; + << "] => mTemplateDeclarations[" << decl2Index << "]" << '\n'; found = true; break; } @@ -3703,9 +3703,9 @@ void TemplateSimplifier::printOut(const std::string & text) const decl2Index = 0; for (const auto & decl2 : mTemplateForwardDeclarations) { if (mapItem.second == decl2.token()) { - std::cout << "mTemplatePartialSpecializationMap[" << mapIndex << "]:" << std::endl; + std::cout << "mTemplatePartialSpecializationMap[" << mapIndex << "]:" << '\n'; std::cout << " mTemplateDeclarations[" << decl1Index - << "] => mTemplateForwardDeclarations[" << decl2Index << "]" << std::endl; + << "] => mTemplateForwardDeclarations[" << decl2Index << "]" << '\n'; break; } decl2Index++; @@ -3717,10 +3717,10 @@ void TemplateSimplifier::printOut(const std::string & text) const } mapIndex++; } - std::cout << "mTemplateInstantiations: " << mTemplateInstantiations.size() << std::endl; + std::cout << "mTemplateInstantiations: " << mTemplateInstantiations.size() << '\n'; count = 0; for (const auto & decl : mTemplateInstantiations) { - std::cout << "mTemplateInstantiations[" << count++ << "]:" << std::endl; + std::cout << "mTemplateInstantiations[" << count++ << "]:" << '\n'; printOut(decl); } } diff --git a/lib/timer.cpp b/lib/timer.cpp index 78a176e9e5f..ceff90ec79f 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -57,7 +57,7 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const // lock the whole logging operation to avoid multiple threads printing their results at the same time std::lock_guard l(stdCoutLock); - std::cout << std::endl; + std::cout << '\n'; size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later! for (std::vector::const_iterator iter=data.cbegin(); iter!=data.cend(); ++iter) { @@ -79,13 +79,13 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const if (!hasParent) overallData.mClocks += iter->second.mClocks; if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5_FILE && mode != SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY) || (ordinal<=5)) { - std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl; + std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << '\n'; } ++ordinal; } const double secOverall = overallData.seconds(); - std::cout << "Overall time: " << secOverall << "s" << std::endl; + std::cout << "Overall time: " << secOverall << "s" << '\n'; } void TimerResults::addResults(const std::string& str, std::clock_t clocks) @@ -129,11 +129,11 @@ void Timer::stop() if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) { const double sec = (double)diff / CLOCKS_PER_SEC; std::lock_guard l(stdCoutLock); - std::cout << mStr << ": " << sec << "s" << std::endl; + std::cout << mStr << ": " << sec << "s" << '\n'; } else if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) { const double sec = (double)diff / CLOCKS_PER_SEC; std::lock_guard l(stdCoutLock); - std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl; + std::cout << "Check time: " << mStr << ": " << sec << "s" << '\n'; } else { if (mTimerResults) mTimerResults->addResults(mStr, diff); diff --git a/lib/token.cpp b/lib/token.cpp index aee3150bd19..5cb8453a5a2 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1208,14 +1208,14 @@ void Token::printOut(const char *title) const { if (title && title[0]) std::cout << "\n### " << title << " ###\n"; - std::cout << stringifyList(stringifyOptions::forPrintOut(), nullptr, nullptr) << std::endl; + std::cout << stringifyList(stringifyOptions::forPrintOut(), nullptr, nullptr) << '\n'; } void Token::printOut(const char *title, const std::vector &fileNames) const { if (title && title[0]) std::cout << "\n### " << title << " ###\n"; - std::cout << stringifyList(stringifyOptions::forPrintOut(), &fileNames, nullptr) << std::endl; + std::cout << stringifyList(stringifyOptions::forPrintOut(), &fileNames, nullptr) << '\n'; } // cppcheck-suppress unusedFunction - used for debugging @@ -1224,7 +1224,7 @@ void Token::printLines(int lines) const const Token *end = this; while (end && end->linenr() < lines + linenr()) end = end->next(); - std::cout << stringifyList(stringifyOptions::forDebugExprId(), nullptr, end) << std::endl; + std::cout << stringifyList(stringifyOptions::forDebugExprId(), nullptr, end) << '\n'; } std::string Token::stringify(const stringifyOptions& options) const @@ -1615,23 +1615,23 @@ static void astStringXml(const Token *tok, nonneg int indent, std::ostream &out) out << " values=\"" << &tok->values() << '\"'; if (!tok->astOperand1() && !tok->astOperand2()) { - out << "/>" << std::endl; + out << "/>" << '\n'; } else { - out << '>' << std::endl; + out << '>' << '\n'; if (tok->astOperand1()) astStringXml(tok->astOperand1(), indent+2U, out); if (tok->astOperand2()) astStringXml(tok->astOperand2(), indent+2U, out); - out << strindent << "" << std::endl; + out << strindent << "" << '\n'; } } void Token::printAst(bool verbose, bool xml, const std::vector &fileNames, std::ostream &out) const { if (!xml) - out << "\n\n##AST" << std::endl; + out << "\n\n##AST" << '\n'; std::set printed; for (const Token *tok = this; tok; tok = tok->next()) { @@ -1642,13 +1642,13 @@ void Token::printAst(bool verbose, bool xml, const std::vector &fil if (xml) { out << "scope() << "\" fileIndex=\"" << tok->fileIndex() << "\" linenr=\"" << tok->linenr() - << "\" column=\"" << tok->column() << "\">" << std::endl; + << "\" column=\"" << tok->column() << "\">" << '\n'; astStringXml(tok, 2U, out); - out << "" << std::endl; + out << "" << '\n'; } else if (verbose) - out << "[" << fileNames[tok->fileIndex()] << ":" << tok->linenr() << "]" << std::endl << tok->astStringVerbose() << std::endl; + out << "[" << fileNames[tok->fileIndex()] << ":" << tok->linenr() << "]" << '\n' << tok->astStringVerbose() << '\n'; else - out << tok->astString(" ") << std::endl; + out << tok->astString(" ") << '\n'; if (tok->str() == "(") tok = tok->link(); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a8b41b5b176..0a5fd305116 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5903,7 +5903,7 @@ void Tokenizer::printDebugOutput(int simplification) const list.front()->printOut(nullptr, list.getFiles()); if (mSettings.xml) - std::cout << "" << std::endl; + std::cout << "" << '\n'; if (mSymbolDatabase) { if (mSettings.xml) @@ -5919,7 +5919,7 @@ void Tokenizer::printDebugOutput(int simplification) const list.front()->printValueFlow(mSettings.xml, std::cout); if (mSettings.xml) - std::cout << "" << std::endl; + std::cout << "" << '\n'; } if (mSymbolDatabase && simplification == 2U && mSettings.debugwarnings) { diff --git a/test/fixture.cpp b/test/fixture.cpp index a4deb169307..6a40156fad5 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -105,7 +105,7 @@ bool TestFixture::prepareTest(const char testname[]) std::putchar('.'); // Use putchar to write through redirection of std::cout/cerr std::fflush(stdout); } else { - std::cout << classname << "::" << mTestname << std::endl; + std::cout << classname << "::" << mTestname << '\n'; } return !dry_run; } @@ -142,7 +142,7 @@ static std::string writestr(const std::string &str, bool gccStyle = false) if (*i == '\n') { ostr << "\\n"; if ((i+1) != str.end() && !gccStyle) - ostr << std::endl; + ostr << '\n'; } else if (*i == '\t') ostr << "\\t"; else if (*i == '\"') @@ -153,7 +153,7 @@ static std::string writestr(const std::string &str, bool gccStyle = false) ostr << "\\x" << std::hex << short{*i}; } if (!str.empty() && !gccStyle) - ostr << std::endl; + ostr << '\n'; else if (gccStyle) ostr << '\"'; return ostr.str(); @@ -163,7 +163,7 @@ bool TestFixture::assert_(const char * const filename, const unsigned int linenr { if (!condition) { ++fails_counter; - errmsg << getLocationStr(filename, linenr) << ": Assertion failed." << std::endl << "_____" << std::endl; + errmsg << getLocationStr(filename, linenr) << ": Assertion failed." << '\n' << "_____" << '\n'; } return condition; } @@ -171,14 +171,14 @@ bool TestFixture::assert_(const char * const filename, const unsigned int linenr void TestFixture::assertEqualsFailed(const char* const filename, const unsigned int linenr, const std::string& expected, const std::string& actual, const std::string& msg) const { ++fails_counter; - errmsg << getLocationStr(filename, linenr) << ": Assertion failed. " << std::endl - << "Expected: " << std::endl - << writestr(expected) << std::endl - << "Actual: " << std::endl - << writestr(actual) << std::endl; + errmsg << getLocationStr(filename, linenr) << ": Assertion failed. " << '\n' + << "Expected: " << '\n' + << writestr(expected) << '\n' + << "Actual: " << '\n' + << writestr(actual) << '\n'; if (!msg.empty()) - errmsg << "Hint:" << std::endl << msg << std::endl; - errmsg << "_____" << std::endl; + errmsg << "Hint:" << '\n' << msg << '\n'; + errmsg << "_____" << '\n'; } bool TestFixture::assertEquals(const char * const filename, const unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const @@ -257,7 +257,7 @@ void TestFixture::todoAssertEquals(const char * const filename, const unsigned i { if (wanted == actual) { errmsg << getLocationStr(filename, linenr) << ": Assertion succeeded unexpectedly. " - << "Result: " << writestr(wanted, true) << std::endl << "_____" << std::endl; + << "Result: " << writestr(wanted, true) << '\n' << "_____" << '\n'; ++succeeded_todos_counter; } else { @@ -284,7 +284,7 @@ void TestFixture::assertThrow(const char * const filename, const unsigned int li { ++fails_counter; errmsg << getLocationStr(filename, linenr) << ": Assertion succeeded. " - << "The expected exception was thrown" << std::endl << "_____" << std::endl; + << "The expected exception was thrown" << '\n' << "_____" << '\n'; } @@ -292,7 +292,7 @@ void TestFixture::assertThrowFail(const char * const filename, const unsigned in { ++fails_counter; errmsg << getLocationStr(filename, linenr) << ": Assertion failed. " - << "The expected exception was not thrown" << std::endl << "_____" << std::endl; + << "The expected exception was not thrown" << '\n' << "_____" << '\n'; } @@ -317,7 +317,7 @@ void TestFixture::assertNoThrowFail(const char * const filename, const unsigned } errmsg << getLocationStr(filename, linenr) << ": Assertion failed. " - << "Unexpected exception was thrown: " << ex_msg << std::endl << "_____" << std::endl; + << "Unexpected exception was thrown: " << ex_msg << '\n' << "_____" << '\n'; } @@ -357,15 +357,15 @@ void TestFixture::run(const std::string &str) } catch (const InternalError& e) { ++fails_counter; - errmsg << classname << "::" << mTestname << " - InternalError: " << e.errorMessage << std::endl; + errmsg << classname << "::" << mTestname << " - InternalError: " << e.errorMessage << '\n'; } catch (const std::exception& error) { ++fails_counter; - errmsg << classname << "::" << mTestname << " - Exception: " << error.what() << std::endl; + errmsg << classname << "::" << mTestname << " - Exception: " << error.what() << '\n'; } catch (...) { ++fails_counter; - errmsg << classname << "::" << mTestname << " - Unknown exception" << std::endl; + errmsg << classname << "::" << mTestname << " - Unknown exception" << '\n'; } } @@ -397,17 +397,17 @@ std::size_t TestFixture::runTests(const options& args) } if (args.summary() && !args.dry_run()) { - std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << std::endl; + std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << '\n'; std::cout << "Number of todos: " << todos_counter; if (succeeded_todos_counter > 0) std::cout << " (" << succeeded_todos_counter << " succeeded)"; - std::cout << std::endl; + std::cout << '\n'; } // calling flush here, to do all output before the error messages (in case the output is buffered) std::cout.flush(); if (args.summary() && !args.dry_run()) { - std::cerr << "Tests failed: " << fails_counter << std::endl << std::endl; + std::cerr << "Tests failed: " << fails_counter << '\n' << '\n'; } std::cerr << errmsg.str(); @@ -417,7 +417,7 @@ std::size_t TestFixture::runTests(const options& args) void TestFixture::reportOut(const std::string & outmsg, Color /*c*/) { - mOutput << outmsg << std::endl; + mOutput << outmsg << '\n'; } void TestFixture::reportErr(const ErrorMessage &msg) @@ -427,7 +427,7 @@ void TestFixture::reportErr(const ErrorMessage &msg) if (msg.severity == Severity::information && msg.id == "normalCheckLevelMaxBranches") return; const std::string errormessage(msg.toString(mVerbose, mTemplateFormat, mTemplateLocation)); - mErrout << errormessage << std::endl; + mErrout << errormessage << '\n'; } void TestFixture::setTemplateFormat(const std::string &templateFormat) diff --git a/test/helpers.cpp b/test/helpers.cpp index 895d924f7cb..da53f3777ac 100644 --- a/test/helpers.cpp +++ b/test/helpers.cpp @@ -80,7 +80,7 @@ ScopedFile::ScopedFile(std::string name, const std::string &content, std::string ScopedFile::~ScopedFile() { const int remove_res = std::remove(mFullPath.c_str()); if (remove_res != 0) { - std::cout << "ScopedFile(" << mFullPath + ") - could not delete file (" << remove_res << ")" << std::endl; + std::cout << "ScopedFile(" << mFullPath + ") - could not delete file (" << remove_res << ")" << '\n'; } if (!mPath.empty() && mPath != Path::getCurrentPath()) { // TODO: remove all files @@ -89,26 +89,26 @@ ScopedFile::~ScopedFile() { std::list files; const std::string res = FileLister::addFiles(files, mPath, {".plist"}, false, PathMatch({})); if (!res.empty()) { - std::cout << "ScopedFile(" << mPath + ") - generating file list failed (" << res << ")" << std::endl; + std::cout << "ScopedFile(" << mPath + ") - generating file list failed (" << res << ")" << '\n'; } for (const auto &f : files) { const std::string &file = f.path(); const int rm_f_res = std::remove(file.c_str()); if (rm_f_res != 0) { - std::cout << "ScopedFile(" << mPath + ") - could not delete '" << file << "' (" << rm_f_res << ")" << std::endl; + std::cout << "ScopedFile(" << mPath + ") - could not delete '" << file << "' (" << rm_f_res << ")" << '\n'; } } #ifdef _WIN32 if (!RemoveDirectoryA(mPath.c_str())) { - std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << GetLastError() << ")" << std::endl; + std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << GetLastError() << ")" << '\n'; } #else const int rmdir_res = rmdir(mPath.c_str()); if (rmdir_res == -1) { const int err = errno; - std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << err << ")" << std::endl; + std::cout << "ScopedFile(" << mFullPath + ") - could not delete folder (" << err << ")" << '\n'; } #endif } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 0c73f301820..ad7de753221 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6645,9 +6645,9 @@ class TestSymbolDatabase : public TestFixture { ASSERT(function != nullptr); if (function) { std::stringstream expected; - expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl; + expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << '\n'; std::stringstream actual; - actual << "Function call on line " << tok->linenr() << " calls function on line " << function->tokenDef->linenr() << std::endl; + actual << "Function call on line " << tok->linenr() << " calls function on line " << function->tokenDef->linenr() << '\n'; ASSERT_EQUALS(expected.str(), actual.str()); } index++; diff --git a/tools/dmake/dmake.cpp b/tools/dmake/dmake.cpp index d4ee7ddb3e0..b983f017a34 100644 --- a/tools/dmake/dmake.cpp +++ b/tools/dmake/dmake.cpp @@ -193,7 +193,7 @@ static int write_vcxproj(const std::string &proj_name, const std::function libfiles; std::string err = getCppFiles(libfiles, "lib/", false); if (!err.empty()) { - std::cerr << err << std::endl; + std::cerr << err << '\n'; return EXIT_FAILURE; } const std::vector libfiles_prio = prioritizelib(libfiles); @@ -423,33 +423,33 @@ int main(int argc, char **argv) std::vector extfiles; err = getCppFiles(extfiles, "externals/", true); if (!err.empty()) { - std::cerr << err << std::endl; + std::cerr << err << '\n'; return EXIT_FAILURE; } std::vector clifiles; err = getCppFiles(clifiles, "cli/", false); if (!err.empty()) { - std::cerr << err << std::endl; + std::cerr << err << '\n'; return EXIT_FAILURE; } std::vector testfiles; err = getCppFiles(testfiles, "test/", false); if (!err.empty()) { - std::cerr << err << std::endl; + std::cerr << err << '\n'; return EXIT_FAILURE; } std::vector toolsfiles; err = getCppFiles(toolsfiles, "tools/dmake/", false); if (!err.empty()) { - std::cerr << err << std::endl; + std::cerr << err << '\n'; return EXIT_FAILURE; } if (libfiles.empty() && clifiles.empty() && testfiles.empty()) { - std::cerr << "No files found. Are you in the correct directory?" << std::endl; + std::cerr << "No files found. Are you in the correct directory?" << '\n'; return EXIT_FAILURE; }