From 4ca1ed14f2d53e5248d1e56da672fbe1ec0fac06 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 1 Nov 2023 03:03:53 +0100 Subject: [PATCH] enabled and fixed `-Wold-style-cast` Clang warnings --- cli/signalhandler.cpp | 12 ++++++------ cli/stacktrace.cpp | 8 ++++---- cmake/compileroptions.cmake | 1 - gui/codeeditor.cpp | 6 +++--- gui/compliancereportdialog.cpp | 2 +- gui/librarydialog.cpp | 2 +- gui/mainwindow.cpp | 20 ++++++++++---------- gui/resultstree.cpp | 2 +- gui/showtypes.cpp | 2 +- gui/statsdialog.cpp | 2 +- lib/check.cpp | 2 +- lib/checkio.cpp | 4 ++-- lib/checknullpointer.cpp | 10 +++++----- lib/checktype.cpp | 6 +++--- lib/clangimport.cpp | 6 +++--- lib/cppcheck.cpp | 12 ++++++------ lib/ctu.cpp | 6 +++--- lib/errorlogger.cpp | 2 +- lib/mathlib.cpp | 28 ++++++++++++++-------------- lib/mathlib.h | 2 +- lib/settings.h | 6 +++--- lib/timer.cpp | 6 +++--- lib/timer.h | 2 +- lib/token.cpp | 4 ++-- lib/tokenize.cpp | 8 ++++---- lib/valueflow.cpp | 4 ++-- lib/xml.h | 2 ++ test/signal/test-signalhandler.cpp | 2 +- test/testclangimport.cpp | 4 ++-- test/testcmdlineparser.cpp | 6 +++--- test/testlibrary.cpp | 4 ++-- test/testmathlib.cpp | 30 +++++++++++++++--------------- test/testpreprocessor.cpp | 14 +++++++------- test/testsymboldatabase.cpp | 28 ++++++++++++++-------------- test/testtimer.cpp | 2 +- test/testvalueflow.cpp | 8 ++++---- 36 files changed, 133 insertions(+), 132 deletions(-) diff --git a/cli/signalhandler.cpp b/cli/signalhandler.cpp index 5b1eb8d4104..1b6fb445b49 100644 --- a/cli/signalhandler.cpp +++ b/cli/signalhandler.cpp @@ -116,9 +116,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) // TODO: separate these two defines #if defined(__linux__) && defined(REG_ERR) const auto* const uc = reinterpret_cast(context); - killid = (pid_t) syscall(SYS_gettid); + killid = static_cast(syscall(SYS_gettid)); if (uc) { - type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2; + type = static_cast(uc->uc_mcontext.gregs[REG_ERR]) & 2; } #else (void)context; @@ -170,7 +170,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) break; } fprintf(output, " (at 0x%lx).\n", - (unsigned long)info->si_addr); + reinterpret_cast(info->si_addr)); break; case SIGFPE: fputs("Internal error: cppcheck received signal ", output); @@ -204,7 +204,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) break; } fprintf(output, " (at 0x%lx).\n", - (unsigned long)info->si_addr); + reinterpret_cast(info->si_addr)); break; case SIGILL: fputs("Internal error: cppcheck received signal ", output); @@ -238,7 +238,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) break; } fprintf(output, " (at 0x%lx).%s\n", - (unsigned long)info->si_addr, + reinterpret_cast(info->si_addr), (isAddressOnStack)?" Stackoverflow?":""); break; case SIGINT: @@ -264,7 +264,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) // cppcheck-suppress knownConditionTrueFalse ; FP (type==-1)? "" : (type==0) ? "reading " : "writing ", - (unsigned long)info->si_addr, + reinterpret_cast(info->si_addr), (isAddressOnStack)?" Stackoverflow?":"" ); break; diff --git a/cli/stacktrace.cpp b/cli/stacktrace.cpp index c9f548ca1d0..53c4fdba6df 100644 --- a/cli/stacktrace.cpp +++ b/cli/stacktrace.cpp @@ -33,7 +33,7 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth // 32 vs. 64bit #define ADDRESSDISPLAYLENGTH ((sizeof(long)==8)?12:8) void *callstackArray[32]= {nullptr}; // the less resources the better... - const int currentdepth = backtrace(callstackArray, (int)getArrayLength(callstackArray)); + const int currentdepth = backtrace(callstackArray, static_cast(getArrayLength(callstackArray))); // set offset to 1 to omit the printing function itself int offset=start_idx+1; // some entries on top are within our own exception handling code or libc if (maxdepth<0) @@ -86,12 +86,12 @@ void print_stacktrace(FILE* output, int start_idx, bool demangling, int maxdepth padLen, 0); if (realnameString) { fprintf(output, "%.*s in %s\n", - (int)(secondBracketAddress-firstBracketAddress-3), firstBracketAddress+3, + static_cast(secondBracketAddress - firstBracketAddress - 3), firstBracketAddress+3, realnameString); } else { fprintf(output, "%.*s in %.*s\n", - (int)(secondBracketAddress-firstBracketAddress-3), firstBracketAddress+3, - (int)(firstBracketAddress-symbolString), symbolString); + static_cast(secondBracketAddress - firstBracketAddress - 3), firstBracketAddress+3, + static_cast(firstBracketAddress - symbolString), symbolString); } } // NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion) - code matches the documented usage diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 108e8da30fd..ada39cea21f 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -108,7 +108,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # TODO: fix and enable these warnings - or move to suppression list below add_compile_options_safe(-Wno-documentation-unknown-command) # TODO: Clang currently does not support all commands add_compile_options_safe(-Wno-unused-exception-parameter) - add_compile_options_safe(-Wno-old-style-cast) add_compile_options_safe(-Wno-sign-conversion) add_compile_options_safe(-Wno-shadow-field-in-constructor) add_compile_options_safe(-Wno-covered-switch-default) diff --git a/gui/codeeditor.cpp b/gui/codeeditor.cpp index ecc3575bc26..8b2634873a4 100644 --- a/gui/codeeditor.cpp +++ b/gui/codeeditor.cpp @@ -425,8 +425,8 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event) QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); - int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); - int bottom = top + (int) blockBoundingRect(block).height(); + int top = static_cast(blockBoundingGeometry(block).translated(contentOffset()).top()); + int bottom = top + static_cast(blockBoundingRect(block).height()); while (block.isValid() && top <= event->rect().bottom()) { if (block.isVisible() && bottom >= event->rect().top()) { @@ -438,7 +438,7 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event) block = block.next(); top = bottom; - bottom = top + (int) blockBoundingRect(block).height(); + bottom = top + static_cast(blockBoundingRect(block).height()); ++blockNumber; } } diff --git a/gui/compliancereportdialog.cpp b/gui/compliancereportdialog.cpp index a19e395fbe0..8e8d523a05a 100644 --- a/gui/compliancereportdialog.cpp +++ b/gui/compliancereportdialog.cpp @@ -197,7 +197,7 @@ void ComplianceReportDialog::save() QCryptographicHash hash(QCryptographicHash::Algorithm::Md5); if (hash.addData(&f)) { for (auto b: hash.result()) - out << QString::number((unsigned char)b,16); + out << QString::number(static_cast(b),16); out << " " << fileName << "\n"; } } diff --git a/gui/librarydialog.cpp b/gui/librarydialog.cpp index 5930983eee4..0cdfb5cf84a 100644 --- a/gui/librarydialog.cpp +++ b/gui/librarydialog.cpp @@ -313,7 +313,7 @@ void LibraryDialog::changeFunction() return; function->comments = mUi->comments->toPlainText(); - function->noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)mUi->noreturn->currentIndex(); + function->noreturn = static_cast(mUi->noreturn->currentIndex()); function->useretval = mUi->useretval->isChecked(); function->leakignore = mUi->leakignore->isChecked(); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 8cf0103aa60..3db9c0c9f0e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -309,7 +309,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : #else constexpr Platform::Type defaultPlatform = Platform::Type::Unspecified; #endif - PlatformData &platform = mPlatforms.get((Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt()); + PlatformData &platform = mPlatforms.get(static_cast(mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt())); platform.mActMainWindow->setChecked(true); mNetworkAccessManager = new QNetworkAccessManager(this); @@ -385,7 +385,7 @@ void MainWindow::loadSettings() mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt()); } - const ReportType reportType = (ReportType)mSettings->value(SETTINGS_REPORT_TYPE, (int)ReportType::normal).toInt(); + const ReportType reportType = static_cast(mSettings->value(SETTINGS_REPORT_TYPE, static_cast(ReportType::normal)).toInt()); mUI->mActionReportNormal->setChecked(reportType <= ReportType::normal); mUI->mActionReportAutosar->setChecked(reportType == ReportType::autosar); mUI->mActionReportCertC->setChecked(reportType == ReportType::certC); @@ -433,7 +433,7 @@ void MainWindow::loadSettings() mUI->mActionToolBarFilter->setChecked(showFilterToolbar); mUI->mToolBarFilter->setVisible(showFilterToolbar); - const Standards::Language enforcedLanguage = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); + const Standards::Language enforcedLanguage = static_cast(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt()); if (enforcedLanguage == Standards::Language::CPP) mUI->mActionEnforceCpp->setChecked(true); else if (enforcedLanguage == Standards::Language::C) @@ -483,7 +483,7 @@ void MainWindow::saveSettings() const mUI->mActionReportMisraCpp2008->isChecked() ? ReportType::misraCpp2008 : mUI->mActionReportMisraCpp2023->isChecked() ? ReportType::misraCpp2023 : ReportType::normal; - mSettings->setValue(SETTINGS_REPORT_TYPE, (int)reportType); + mSettings->setValue(SETTINGS_REPORT_TYPE, static_cast(reportType)); // Show * states mSettings->setValue(SETTINGS_SHOW_STYLE, mUI->mActionShowStyle->isChecked()); @@ -559,7 +559,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons p.ignorePaths(v); if (!mProjectFile->getAnalyzeAllVsConfigs()) { - const Platform::Type platform = (Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt(); + const Platform::Type platform = static_cast(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()); std::vector configurations; const QStringList configs = mProjectFile->getVsConfigurations(); std::transform(configs.cbegin(), configs.cend(), std::back_inserter(configurations), [](const QString& e) { @@ -1125,7 +1125,7 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs) settings.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString()); } else { for (int i = Platform::Type::Native; i <= Platform::Type::Unix64; i++) { - const auto p = (Platform::Type)i; + const auto p = static_cast(i); if (platform == Platform::toString(p)) { settings.platform.set(p); break; @@ -1205,10 +1205,10 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs) settings.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt(); settings.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool()); if (!mProjectFile || settings.platform.type == Platform::Type::Unspecified) - settings.platform.set((Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()); + settings.platform.set(static_cast(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt())); settings.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString()); settings.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString()); - settings.enforcedLang = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); + settings.enforcedLang = static_cast(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt()); settings.jobs = std::max(settings.jobs, 1u); @@ -2133,7 +2133,7 @@ void MainWindow::updateMRUMenuItems() if (removed) mSettings->setValue(SETTINGS_MRU_PROJECTS, projects); - const int numRecentProjects = qMin(projects.size(), (int)MaxRecentProjects); + const int numRecentProjects = qMin(projects.size(), static_cast(MaxRecentProjects)); for (int i = 0; i < numRecentProjects; i++) { const QString filename = QFileInfo(projects[i]).fileName(); const QString text = QString("&%1 %2").arg(i + 1).arg(filename); @@ -2172,7 +2172,7 @@ void MainWindow::selectPlatform() { auto *action = qobject_cast(sender()); if (action) { - const Platform::Type platform = (Platform::Type) action->data().toInt(); + const Platform::Type platform = static_cast(action->data().toInt()); mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform); } } diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index bbce48c2a6a..3ab9e2602ff 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -1006,7 +1006,7 @@ void ResultsTree::copy() QString inconclusive = itemdata[INCONCLUSIVE].toBool() ? ",inconclusive" : ""; text += itemdata[FILENAME].toString() + ':' + QString::number(itemdata[LINE].toInt()) + ':' + QString::number(itemdata[COLUMN].toInt()) + ": " - + QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)itemdata[SEVERITY].toInt()))) + inconclusive + + QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity(static_cast(itemdata[SEVERITY].toInt())))) + inconclusive + ": " + itemdata[MESSAGE].toString() + " [" diff --git a/gui/showtypes.cpp b/gui/showtypes.cpp index 4b830f3d503..fc8afc5050a 100644 --- a/gui/showtypes.cpp +++ b/gui/showtypes.cpp @@ -89,7 +89,7 @@ ShowTypes::ShowType ShowTypes::VariantToShowType(const QVariant &data) if (value < ShowTypes::ShowStyle || value > ShowTypes::ShowErrors) { return ShowTypes::ShowNone; } - return (ShowTypes::ShowType)value; + return static_cast(value); } void ShowTypes::load() diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index c2965d1328a..e9580f9ffea 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -199,7 +199,7 @@ void StatsDialog::pdfExport() .arg(tr("Information messages")) .arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowInformation)); - QString fileName = QFileDialog::getSaveFileName((QWidget*)nullptr, tr("Export PDF"), QString(), "*.pdf"); + QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Export PDF"), QString(), "*.pdf"); if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); } diff --git a/lib/check.cpp b/lib/check.cpp index e2537cb6455..29285f14833 100644 --- a/lib/check.cpp +++ b/lib/check.cpp @@ -106,7 +106,7 @@ std::string Check::getMessageId(const ValueFlow::Value &value, const char id[]) if (value.condition != nullptr) return id + std::string("Cond"); if (value.safe) - return std::string("safe") + (char)std::toupper(id[0]) + (id + 1); + return std::string("safe") + static_cast(std::toupper(id[0])) + (id + 1); return id; } diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 64909429988..8276ab00bd9 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -445,7 +445,7 @@ void CheckIO::invalidScanf() format = false; } - else if (std::isalpha((unsigned char)formatstr[i]) || formatstr[i] == '[') { + else if (std::isalpha(static_cast(formatstr[i])) || formatstr[i] == '[') { if (formatstr[i] == 's' || formatstr[i] == '[' || formatstr[i] == 'S' || (formatstr[i] == 'l' && formatstr[i+1] == 's')) // #3490 - field width limits are only necessary for string input invalidScanfError(tok); format = false; @@ -645,7 +645,7 @@ void CheckIO::checkFormatString(const Token * const tok, std::string width; int parameterPosition = 0; bool hasParameterPosition = false; - while (i != formatString.cend() && *i != '[' && !std::isalpha((unsigned char)*i)) { + while (i != formatString.cend() && *i != '[' && !std::isalpha(static_cast(*i))) { if (*i == '*') { skip = true; if (scan) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 04b3232e06f..d59b42d17eb 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -106,7 +106,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list(*i))) { if (*i == '*') { if (scan) _continue = true; @@ -474,11 +474,11 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var std::string id = "nullPointer"; if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) { - errmsg = "If memory allocation fails, then there is a " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); + errmsg = "If memory allocation fails, then there is a " + (static_cast(std::tolower(errmsg[0])) + errmsg.substr(1)); id += "OutOfMemory"; } else if (value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) { - errmsg = "If resource allocation fails, then there is a " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); + errmsg = "If resource allocation fails, then there is a " + (static_cast(std::tolower(errmsg[0])) + errmsg.substr(1)); id += "OutOfResources"; } @@ -553,11 +553,11 @@ void CheckNullPointer::pointerArithmeticError(const Token* tok, const ValueFlow: std::string id = "nullPointerArithmetic"; if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfMemory) { - errmsg = "If memory allocation fails: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); + errmsg = "If memory allocation fails: " + (static_cast(std::tolower(errmsg[0])) + errmsg.substr(1)); id += "OutOfMemory"; } else if (value && value->unknownFunctionReturn == ValueFlow::Value::UnknownFunctionReturn::outOfResources) { - errmsg = "If resource allocation fails: " + ((char)std::tolower(errmsg[0]) + errmsg.substr(1)); + errmsg = "If resource allocation fails: " + (static_cast(std::tolower(errmsg[0])) + errmsg.substr(1)); id += "OutOfResources"; } diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 646e15efcb4..3498e161aae 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -200,7 +200,7 @@ void CheckType::checkIntegerOverflow() continue; // max value according to platform settings. - const MathLib::bigint maxvalue = (((MathLib::biguint)1) << (bits - 1)) - 1; + const MathLib::bigint maxvalue = (static_cast(1) << (bits - 1)) - 1; // is there a overflow result value bool isOverflow = true; @@ -213,7 +213,7 @@ void CheckType::checkIntegerOverflow() continue; // For left shift, it's common practice to shift into the sign bit - if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits)) + if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (static_cast(1) << bits)) continue; integerOverflowError(tok, *value, isOverflow); @@ -507,7 +507,7 @@ void CheckType::checkFloatToIntegerOverflow(const Token *tok, const ValueType *v bits = mSettings->platform.long_long_bit; else continue; - if (bits < MathLib::bigint_bits && f.floatValue >= (((MathLib::biguint)1) << bits)) + if (bits < MathLib::bigint_bits && f.floatValue >= (static_cast(1) << bits)) floatToIntegerOverflowError(tok, f); } } diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 95d6b8cde1b..c5962268998 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -139,11 +139,11 @@ static std::vector splitString(const std::string &line) pos2 = line.find('\"', pos1+1); else if (line[pos1] == '\'') { pos2 = line.find('\'', pos1+1); - if (pos2 < (int)line.size() - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) + if (pos2 < static_cast(line.size()) - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0) pos2 = line.find('\'', pos2 + 3); } else { pos2 = pos1; - while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum((unsigned char)line[pos2]))) + while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum(static_cast(line[pos2])))) ++pos2; if (pos2 > pos1 && pos2 < line.size() && line[pos2] == '<' && std::isalpha(line[pos1])) { int tlevel = 1; @@ -1267,7 +1267,7 @@ Token *clangimport::AstNode::createTokens(TokenList &tokenList) return addtoken(tokenList, getSpelling()); } if (nodeType == UnaryOperator) { - int index = (int)mExtTokens.size() - 1; + int index = static_cast(mExtTokens.size()) - 1; while (index > 0 && mExtTokens[index][0] != '\'') --index; Token *unop = addtoken(tokenList, unquote(mExtTokens[index])); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c7b9f2b2dbf..f7954776246 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1264,7 +1264,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string // collected after all files are processed if (!mSettings.useSingleJob()) { // TODO: check result? - SuppressionList::reportUnmatchedSuppressions(mSuppressions.nomsg.getUnmatchedLocalSuppressions(file, (bool)mUnusedFunctionsCheck), mErrorLogger); + SuppressionList::reportUnmatchedSuppressions(mSuppressions.nomsg.getUnmatchedLocalSuppressions(file, static_cast(mUnusedFunctionsCheck)), mErrorLogger); } } @@ -1594,8 +1594,8 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list) int pos = 0; int ovector[30]= {0}; - while (pos < (int)str.size()) { - const int pcreExecRet = pcre_exec(re, pcreExtra, str.c_str(), (int)str.size(), pos, 0, ovector, 30); + while (pos < static_cast(str.size())) { + const int pcreExecRet = pcre_exec(re, pcreExtra, str.c_str(), static_cast(str.size()), pos, 0, ovector, 30); if (pcreExecRet < 0) { const std::string errorMessage = pcreErrorCodeToString(pcreExecRet); if (!errorMessage.empty()) { @@ -1610,11 +1610,11 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list) } break; } - const auto pos1 = (unsigned int)ovector[0]; - const auto pos2 = (unsigned int)ovector[1]; + const auto pos1 = static_cast(ovector[0]); + const auto pos2 = static_cast(ovector[1]); // jump to the end of the match for the next pcre_exec - pos = (int)pos2; + pos = static_cast(pos2); // determine location.. int fileIndex = 0; diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 3d11e5fa4f6..833a4dfda4b 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -104,7 +104,7 @@ std::string CTU::FileInfo::FunctionCall::toXmlString() const << " " << ATTR_CALL_ARGEXPR << "=\"" << ErrorLogger::toxml(callArgumentExpression) << "\"" << " " << ATTR_CALL_ARGVALUETYPE << "=\"" << static_cast(callValueType) << "\"" << " " << ATTR_CALL_ARGVALUE << "=\"" << callArgValue.value << "\"" - << " " << ATTR_CALL_UNKNOWN_FUNCTION_RETURN << "=\"" << (int)callArgValue.unknownFunctionReturn << "\""; + << " " << ATTR_CALL_UNKNOWN_FUNCTION_RETURN << "=\"" << static_cast(callArgValue.unknownFunctionReturn) << "\""; if (warning) out << " " << ATTR_WARNING << "=\"true\""; if (callValuePath.empty()) @@ -202,11 +202,11 @@ bool CTU::FileInfo::FunctionCall::loadFromXml(const tinyxml2::XMLElement *xmlEle return false; bool error=false; callArgumentExpression = readAttrString(xmlElement, ATTR_CALL_ARGEXPR, &error); - callValueType = (ValueFlow::Value::ValueType)readAttrInt(xmlElement, ATTR_CALL_ARGVALUETYPE, &error); + callValueType = static_cast(readAttrInt(xmlElement, ATTR_CALL_ARGVALUETYPE, &error)); callArgValue.value = readAttrInt(xmlElement, ATTR_CALL_ARGVALUE, &error); const auto ufr = readAttrInt(xmlElement, ATTR_CALL_UNKNOWN_FUNCTION_RETURN, &error); // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - TODO: fix this - #13726 - callArgValue.unknownFunctionReturn = (ValueFlow::Value::UnknownFunctionReturn)(ufr>=0 && ufr <=0xff ? ufr : 0xff); + callArgValue.unknownFunctionReturn = static_cast(ufr>=0 && ufr <=0xff ? ufr : 0xff); const char *w = xmlElement->Attribute(ATTR_WARNING); warning = w && std::strcmp(w, "true") == 0; for (const tinyxml2::XMLElement *e2 = xmlElement->FirstChildElement(); !error && e2; e2 = e2->NextSiblingElement()) { diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index b035856213f..e30d0f0dabf 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -472,7 +472,7 @@ std::string ErrorMessage::fixInvalidChars(const std::string& raw) } else { std::ostringstream es; // straight cast to (unsigned) doesn't work out. - const unsigned uFrom = (unsigned char)*from; + const unsigned uFrom = static_cast(*from); es << '\\' << std::setbase(8) << std::setw(3) << std::setfill('0') << uFrom; result += es.str(); } diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 6ab0247abba..54240fa4f2f 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -152,34 +152,34 @@ MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const Mat } else if (temp.mIsUnsigned) { switch (op) { case '+': - temp.mIntValue += (unsigned long long)v2.mIntValue; + temp.mIntValue += static_cast(v2.mIntValue); break; case '-': - temp.mIntValue -= (unsigned long long)v2.mIntValue; + temp.mIntValue -= static_cast(v2.mIntValue); break; case '*': - temp.mIntValue *= (unsigned long long)v2.mIntValue; + temp.mIntValue *= static_cast(v2.mIntValue); break; case '/': if (v2.mIntValue == 0) throw InternalError(nullptr, "Internal Error: Division by zero"); if (v1.mIntValue == std::numeric_limits::min() && std::abs(v2.mIntValue)<=1) throw InternalError(nullptr, "Internal Error: Division overflow"); - temp.mIntValue /= (unsigned long long)v2.mIntValue; + temp.mIntValue /= static_cast(v2.mIntValue); break; case '%': if (v2.mIntValue == 0) throw InternalError(nullptr, "Internal Error: Division by zero"); - temp.mIntValue %= (unsigned long long)v2.mIntValue; + temp.mIntValue %= static_cast(v2.mIntValue); break; case '&': - temp.mIntValue &= (unsigned long long)v2.mIntValue; + temp.mIntValue &= static_cast(v2.mIntValue); break; case '|': - temp.mIntValue |= (unsigned long long)v2.mIntValue; + temp.mIntValue |= static_cast(v2.mIntValue); break; case '^': - temp.mIntValue ^= (unsigned long long)v2.mIntValue; + temp.mIntValue ^= static_cast(v2.mIntValue); break; default: throw InternalError(nullptr, "Unhandled calculation"); @@ -238,9 +238,9 @@ int MathLib::value::compare(const MathLib::value &v) const } if (temp.mIsUnsigned) { - if ((unsigned long long)mIntValue < (unsigned long long)v.mIntValue) + if (static_cast(mIntValue) < static_cast(v.mIntValue)) return -1; - if ((unsigned long long)mIntValue > (unsigned long long)v.mIntValue) + if (static_cast(mIntValue) > static_cast(v.mIntValue)) return 1; return 0; } @@ -338,7 +338,7 @@ MathLib::biguint MathLib::toBigUNumber(const std::string & str, const Token * co // Use min/max values as an approximation. See #5843 // TODO: bail out when we are out of range? const double doubleval = toDoubleNumber(str, tok); - if (doubleval > (double)std::numeric_limits::max()) + if (doubleval > static_cast(std::numeric_limits::max())) return std::numeric_limits::max(); // cast to bigint to avoid UBSAN warning about negative double being out-of-range return static_cast(static_cast(doubleval)); @@ -382,7 +382,7 @@ MathLib::bigint MathLib::toBigNumber(const std::string & str, const Token * cons if (isIntHex(str)) { try { const biguint ret = std::stoull(str, nullptr, 16); - return (bigint)ret; + return static_cast(ret); } catch (const std::out_of_range& /*e*/) { throw InternalError(tok, "Internal Error. MathLib::toBigNumber: out_of_range: " + str); } catch (const std::invalid_argument& /*e*/) { @@ -422,9 +422,9 @@ MathLib::bigint MathLib::toBigNumber(const std::string & str, const Token * cons // Use min/max values as an approximation. See #5843 // TODO: bail out when we are out of range? const double doubleval = toDoubleNumber(str, tok); - if (doubleval > (double)std::numeric_limits::max()) + if (doubleval > static_cast(std::numeric_limits::max())) return std::numeric_limits::max(); - if (doubleval < (double)std::numeric_limits::min()) + if (doubleval < static_cast(std::numeric_limits::min())) return std::numeric_limits::min(); return static_cast(doubleval); } diff --git a/lib/mathlib.h b/lib/mathlib.h index 54e3106d132..6b415d3bb55 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -70,7 +70,7 @@ class CPPCHECKLIB MathLib { } double getDoubleValue() const { - return isFloat() ? mDoubleValue : (double)mIntValue; + return isFloat() ? mDoubleValue : static_cast(mIntValue); } static value calc(char op, const value &v1, const value &v2); diff --git a/lib/settings.h b/lib/settings.h index 289abec8950..8081bd8ba0f 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -69,16 +69,16 @@ class SimpleEnableGroup { mFlags = 0xFFFFFFFF; } bool isEnabled(T flag) const { - return (mFlags & (1U << (uint32_t)flag)) != 0; + return (mFlags & (1U << static_cast(flag))) != 0; } void enable(T flag) { - mFlags |= (1U << (uint32_t)flag); + mFlags |= (1U << static_cast(flag)); } void enable(SimpleEnableGroup group) { mFlags |= group.intValue(); } void disable(T flag) { - mFlags &= ~(1U << (uint32_t)flag); + mFlags &= ~(1U << static_cast(flag)); } void disable(SimpleEnableGroup group) { mFlags &= ~(group.intValue()); diff --git a/lib/timer.cpp b/lib/timer.cpp index 10181494893..4b1f07d5de3 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -62,7 +62,7 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later! for (auto iter=data.cbegin(); iter!=data.cend(); ++iter) { const double sec = iter->second.seconds(); - const double secAverage = sec / (double)(iter->second.mNumberOfResults); + const double secAverage = sec / static_cast(iter->second.mNumberOfResults); bool hasParent = false; { // Do not use valueFlow.. in "Overall time" because those are included in Tokenizer already @@ -127,11 +127,11 @@ void Timer::stop() const std::clock_t diff = end - mStart; if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) { - const double sec = (double)diff / CLOCKS_PER_SEC; + const double sec = static_cast(diff) / CLOCKS_PER_SEC; std::lock_guard l(stdCoutLock); std::cout << mStr << ": " << sec << "s" << std::endl; } else if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL) { - const double sec = (double)diff / CLOCKS_PER_SEC; + const double sec = static_cast(diff) / CLOCKS_PER_SEC; std::lock_guard l(stdCoutLock); std::cout << "Check time: " << mStr << ": " << sec << "s" << std::endl; } else { diff --git a/lib/timer.h b/lib/timer.h index 077a4ab6130..e67e170902e 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -51,7 +51,7 @@ struct TimerResultsData { long mNumberOfResults{}; double seconds() const { - const double ret = (double)((unsigned long)mClocks) / (double)CLOCKS_PER_SEC; + const double ret = static_cast(static_cast(mClocks)) / static_cast(CLOCKS_PER_SEC); return ret; } }; diff --git a/lib/token.cpp b/lib/token.cpp index 685e8fe95fe..1bb62dd8c5d 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -124,7 +124,7 @@ void Token::update_property_info() tokType(eChar); isLong(isPrefixStringCharLiteral(mStr, '\'', "L")); } - else if (std::isalpha((unsigned char)mStr[0]) || mStr[0] == '_' || mStr[0] == '$') { // Name + else if (std::isalpha(static_cast(mStr[0])) || mStr[0] == '_' || mStr[0] == '$') { // Name if (mImpl->mVarId) tokType(eVariable); else if (mTokensFrontBack.list.isKeyword(mStr)) { @@ -761,7 +761,7 @@ nonneg int Token::getStrArraySize(const Token *tok) // cppcheck-suppress shadowFunction - TODO: fix this const std::string str(getStringLiteral(tok->str())); int sizeofstring = 1; - for (int i = 0; i < (int)str.size(); i++) { + for (int i = 0; i < static_cast(str.size()); i++) { if (str[i] == '\\') ++i; ++sizeofstring; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 691ee21f102..86f26e47533 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8147,7 +8147,7 @@ void Tokenizer::unhandledCharLiteral(const Token *tok, const std::string& msg) c { std::string s = tok ? (" " + tok->str()) : ""; for (std::size_t i = 0; i < s.size(); ++i) { - if ((unsigned char)s[i] >= 0x80) + if (static_cast(s[i]) >= 0x80) s.clear(); } @@ -8949,7 +8949,7 @@ std::string Tokenizer::simplifyString(const std::string &source) int sz = 0; // size of stringdata if (str[i+1] == 'x') { sz = 2; - while (sz < 4 && std::isxdigit((unsigned char)str[i+sz])) + while (sz < 4 && std::isxdigit(static_cast(str[i+sz]))) sz++; if (sz > 2) { std::istringstream istr(str.substr(i+2, sz-2)); @@ -8961,14 +8961,14 @@ std::string Tokenizer::simplifyString(const std::string &source) sz++; std::istringstream istr(str.substr(i+1, sz-1)); istr >> std::oct >> c; - str = str.replace(i, sz, std::string(1U, (char)c)); + str = str.replace(i, sz, std::string(1U, static_cast(c))); continue; } if (sz <= 2) i++; else if (i+sz < str.size()) - str.replace(i, sz, std::string(1U, (char)c)); + str.replace(i, sz, std::string(1U, static_cast(c))); else str.replace(i, str.size() - i - 1U, "a"); } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c8d03755789..4949362d9a2 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1008,10 +1008,10 @@ static void valueFlowBitAnd(TokenList& tokenlist, const Settings& settings) continue; int bit = 0; - while (bit <= (MathLib::bigint_bits - 2) && ((((MathLib::bigint)1) << bit) < number)) + while (bit <= (MathLib::bigint_bits - 2) && ((static_cast(1) << bit) < number)) ++bit; - if ((((MathLib::bigint)1) << bit) == number) { + if ((static_cast(1) << bit) == number) { setTokenValue(tok, ValueFlow::Value(0), settings); setTokenValue(tok, ValueFlow::Value(number), settings); } diff --git a/lib/xml.h b/lib/xml.h index c5bc8461978..90c462bf72a 100644 --- a/lib/xml.h +++ b/lib/xml.h @@ -29,6 +29,7 @@ SUPPRESS_WARNING_CLANG_PUSH("-Wzero-as-null-pointer-constant") SUPPRESS_WARNING_CLANG_PUSH("-Wsuggest-destructor-override") SUPPRESS_WARNING_CLANG_PUSH("-Winconsistent-missing-destructor-override") SUPPRESS_WARNING_CLANG_PUSH("-Wformat") // happens with libc++ only +SUPPRESS_WARNING_CLANG_PUSH("-Wold-style-cast") #include // IWYU pragma: export @@ -36,6 +37,7 @@ SUPPRESS_WARNING_CLANG_POP SUPPRESS_WARNING_CLANG_POP SUPPRESS_WARNING_CLANG_POP SUPPRESS_WARNING_CLANG_POP +SUPPRESS_WARNING_CLANG_POP #if defined(__GNUC__) && (__GNUC__ >= 14) SUPPRESS_WARNING_GCC_POP #endif diff --git a/test/signal/test-signalhandler.cpp b/test/signal/test-signalhandler.cpp index 929d53c6663..335a9426d5f 100644 --- a/test/signal/test-signalhandler.cpp +++ b/test/signal/test-signalhandler.cpp @@ -49,7 +49,7 @@ /*static*/ void my_segv() // NOLINT(misc-use-internal-linkage) { // cppcheck-suppress nullPointer - ++*(int*)nullptr; // NOLINT(clang-analyzer-core.NullDereference) + ++*static_cast(nullptr); // NOLINT(clang-analyzer-core.NullDereference) } #if !defined(__APPLE__) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 795d26358dd..be1dbd21613 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -1138,8 +1138,8 @@ class TestClangImport : public TestFixture { const Scope *scope = db->functionScopes[0]; const Function *func = scope->function; ASSERT_EQUALS(2, func->argCount()); - ASSERT_EQUALS(0, (long long)func->getArgumentVar(0)->nameToken()); - ASSERT_EQUALS(0, (long long)func->getArgumentVar(1)->nameToken()); + ASSERT(!func->getArgumentVar(0)->nameToken()); + ASSERT(!func->getArgumentVar(1)->nameToken()); } void symbolDatabaseFunction3() { // #9640 diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 91996444e54..52b72329f49 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -585,7 +585,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "file.cpp"}; ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); - ASSERT_EQUALS(1, (int)parser->getPathNames().size()); + ASSERT_EQUALS(1, parser->getPathNames().size()); ASSERT_EQUALS("file.cpp", parser->getPathNames().at(0)); } @@ -593,7 +593,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "src"}; ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv)); - ASSERT_EQUALS(1, (int)parser->getPathNames().size()); + ASSERT_EQUALS(1, parser->getPathNames().size()); ASSERT_EQUALS("src", parser->getPathNames().at(0)); } @@ -601,7 +601,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "-v"}; ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv)); - ASSERT_EQUALS(0, (int)parser->getPathNames().size()); + ASSERT_EQUALS(0, parser->getPathNames().size()); ASSERT_EQUALS("cppcheck: error: no C or C++ source files found.\n", logger->str()); } diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index f3ddf3fb0aa..002237a39ba 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -983,7 +983,7 @@ class TestLibrary : public TestFixture { ASSERT(!library.detectContainer(var.tokens())); TODO_ASSERT(library.detectIterator(var.tokens())); bool isIterator = false; - TODO_ASSERT_EQUALS((intptr_t)&F, 0, (intptr_t)library.detectContainerOrIterator(var.tokens(), &isIterator)); + TODO_ASSERT_EQUALS(reinterpret_cast(&F), 0, reinterpret_cast(library.detectContainerOrIterator(var.tokens(), &isIterator))); TODO_ASSERT(isIterator); } @@ -993,7 +993,7 @@ class TestLibrary : public TestFixture { ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); bool isIterator = false; - TODO_ASSERT_EQUALS((intptr_t)&F, 0, (intptr_t)library.detectContainerOrIterator(var.tokens(), &isIterator, true)); + TODO_ASSERT_EQUALS(reinterpret_cast(&F), 0, reinterpret_cast(library.detectContainerOrIterator(var.tokens(), &isIterator, true))); TODO_ASSERT(isIterator); } } diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 5446d23bc3b..ee38deb84e3 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -325,11 +325,11 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS(-1, MathLib::toBigNumber("-10.0E-1")); // from char - ASSERT_EQUALS((int)('A'), MathLib::toBigNumber("'A'")); - ASSERT_EQUALS((int)('\x10'), MathLib::toBigNumber("'\\x10'")); - ASSERT_EQUALS((int)('\100'), MathLib::toBigNumber("'\\100'")); - ASSERT_EQUALS((int)('\200'), MathLib::toBigNumber("'\\200'")); - ASSERT_EQUALS((int)(L'A'), MathLib::toBigNumber("L'A'")); + ASSERT_EQUALS(static_cast('A'), MathLib::toBigNumber("'A'")); + ASSERT_EQUALS(static_cast('\x10'), MathLib::toBigNumber("'\\x10'")); + ASSERT_EQUALS(static_cast('\100'), MathLib::toBigNumber("'\\100'")); + ASSERT_EQUALS(static_cast('\200'), MathLib::toBigNumber("'\\200'")); + ASSERT_EQUALS(static_cast(L'A'), MathLib::toBigNumber("L'A'")); ASSERT_EQUALS(-8552249625308161526, MathLib::toBigNumber("0x89504e470d0a1a0a")); ASSERT_EQUALS(-8481036456200365558, MathLib::toBigNumber("0x8a4d4e470d0a1a0a")); @@ -501,11 +501,11 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS(-1, MathLib::toBigUNumber("-10.0E-1")); // from char - ASSERT_EQUALS((int)('A'), MathLib::toBigUNumber("'A'")); - ASSERT_EQUALS((int)('\x10'), MathLib::toBigUNumber("'\\x10'")); - ASSERT_EQUALS((int)('\100'), MathLib::toBigUNumber("'\\100'")); - ASSERT_EQUALS((int)('\200'), MathLib::toBigUNumber("'\\200'")); - ASSERT_EQUALS((int)(L'A'), MathLib::toBigUNumber("L'A'")); + ASSERT_EQUALS(static_cast('A'), MathLib::toBigUNumber("'A'")); + ASSERT_EQUALS(static_cast('\x10'), MathLib::toBigUNumber("'\\x10'")); + ASSERT_EQUALS(static_cast('\100'), MathLib::toBigUNumber("'\\100'")); + ASSERT_EQUALS(static_cast('\200'), MathLib::toBigUNumber("'\\200'")); + ASSERT_EQUALS(static_cast(L'A'), MathLib::toBigUNumber("L'A'")); ASSERT_EQUALS(9894494448401390090ULL, MathLib::toBigUNumber("0x89504e470d0a1a0a")); ASSERT_EQUALS(9965707617509186058ULL, MathLib::toBigUNumber("0x8a4d4e470d0a1a0a")); @@ -673,11 +673,11 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS_DOUBLE(0.0625, MathLib::toDoubleNumber("0x.1P0"), 0.000001); // from char - ASSERT_EQUALS_DOUBLE((double)('A'), MathLib::toDoubleNumber("'A'"), 0.000001); - ASSERT_EQUALS_DOUBLE((double)('\x10'), MathLib::toDoubleNumber("'\\x10'"), 0.000001); - ASSERT_EQUALS_DOUBLE((double)('\100'), MathLib::toDoubleNumber("'\\100'"), 0.000001); - ASSERT_EQUALS_DOUBLE((double)('\200'), MathLib::toDoubleNumber("'\\200'"), 0.000001); - ASSERT_EQUALS_DOUBLE((double)(L'A'), MathLib::toDoubleNumber("L'A'"), 0.000001); + ASSERT_EQUALS_DOUBLE(static_cast('A'), MathLib::toDoubleNumber("'A'"), 0.000001); + ASSERT_EQUALS_DOUBLE(static_cast('\x10'), MathLib::toDoubleNumber("'\\x10'"), 0.000001); + ASSERT_EQUALS_DOUBLE(static_cast('\100'), MathLib::toDoubleNumber("'\\100'"), 0.000001); + ASSERT_EQUALS_DOUBLE(static_cast('\200'), MathLib::toDoubleNumber("'\\200'"), 0.000001); + ASSERT_EQUALS_DOUBLE(static_cast(L'A'), MathLib::toDoubleNumber("L'A'"), 0.000001); ASSERT_THROW_INTERNAL_EQUALS(MathLib::toDoubleNumber("invalid"), INTERNAL, "Internal Error. MathLib::toDoubleNumber: conversion failed: invalid"); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index fe893858dba..692609ed519 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1694,7 +1694,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(1, (int)actual.size()); + ASSERT_EQUALS(1, actual.size()); ASSERT_EQUALS("\n\n\n\nB", actual.at("")); } @@ -1708,7 +1708,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(1, (int)actual.size()); + ASSERT_EQUALS(1, actual.size()); ASSERT_EQUALS("\n\n$1", actual.at("")); } @@ -1722,7 +1722,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(1, (int)actual.size()); + ASSERT_EQUALS(1, actual.size()); ASSERT_EQUALS("\n\n$1", actual.at("")); } @@ -1736,7 +1736,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(1, (int)actual.size()); + ASSERT_EQUALS(1, actual.size()); ASSERT_EQUALS("\n\n$1", actual.at("")); } @@ -1751,7 +1751,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(1, (int)actual.size()); + ASSERT_EQUALS(1, actual.size()); ASSERT_EQUALS("\n\n\n\n$1", actual.at("")); } } @@ -1828,7 +1828,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(4, (int)actual.size()); + ASSERT_EQUALS(4, actual.size()); ASSERT(actual.find("") != actual.end()); ASSERT(actual.find("BAR") != actual.end()); ASSERT(actual.find("FOO") != actual.end()); @@ -1845,7 +1845,7 @@ class TestPreprocessor : public TestFixture { const std::map actual = PreprocessorHelper::getcode(settings0, *this, filedata); // Compare results.. - ASSERT_EQUALS(1, (int)actual.size()); + ASSERT_EQUALS(1, actual.size()); ASSERT_EQUALS("char a [ ] = \"#endfile\" ;\nchar b [ ] = \"#endfile\" ;", actual.at("")); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 8d22ce8fd1f..7990f4ce7d9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6198,7 +6198,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(4U, scope->enumeratorList.size()); ASSERT(scope->enumeratorList[0].name->enumerator() == &scope->enumeratorList[0]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[0].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[0].name->tokType()); ASSERT(scope->enumeratorList[0].scope == &*scope); ASSERT_EQUALS("O1", scope->enumeratorList[0].name->str()); ASSERT(scope->enumeratorList[0].start == nullptr); @@ -6207,7 +6207,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(0, scope->enumeratorList[0].value); ASSERT(scope->enumeratorList[1].name->enumerator() == &scope->enumeratorList[1]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[1].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[1].name->tokType()); ASSERT(scope->enumeratorList[1].scope == &*scope); ASSERT_EQUALS("O2", scope->enumeratorList[1].name->str()); ASSERT(scope->enumeratorList[1].start == nullptr); @@ -6216,7 +6216,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(1, scope->enumeratorList[1].value); ASSERT(scope->enumeratorList[2].name->enumerator() == &scope->enumeratorList[2]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[2].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[2].name->tokType()); ASSERT(scope->enumeratorList[2].scope == &*scope); ASSERT_EQUALS("O3", scope->enumeratorList[2].name->str()); ASSERT(scope->enumeratorList[2].start != nullptr); @@ -6225,7 +6225,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(5, scope->enumeratorList[2].value); ASSERT(scope->enumeratorList[3].name->enumerator() == &scope->enumeratorList[3]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[3].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[3].name->tokType()); ASSERT(scope->enumeratorList[3].scope == &*scope); ASSERT_EQUALS("O4", scope->enumeratorList[3].name->str()); ASSERT(scope->enumeratorList[3].start == nullptr); @@ -6239,7 +6239,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(3U, scope->enumeratorList.size()); ASSERT(scope->enumeratorList[0].name->enumerator() == &scope->enumeratorList[0]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[0].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[0].name->tokType()); ASSERT(scope->enumeratorList[0].scope == &*scope); ASSERT_EQUALS("E1", scope->enumeratorList[0].name->str()); ASSERT(scope->enumeratorList[0].start != nullptr); @@ -6248,7 +6248,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(1, scope->enumeratorList[0].value); ASSERT(scope->enumeratorList[1].name->enumerator() == &scope->enumeratorList[1]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[1].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[1].name->tokType()); ASSERT(scope->enumeratorList[1].scope == &*scope); ASSERT_EQUALS("E2", scope->enumeratorList[1].name->str()); ASSERT(scope->enumeratorList[1].start == nullptr); @@ -6257,7 +6257,7 @@ class TestSymbolDatabase : public TestFixture { ASSERT_EQUALS(2, scope->enumeratorList[1].value); ASSERT(scope->enumeratorList[2].name->enumerator() == &scope->enumeratorList[2]); - ASSERT_EQUALS((unsigned int)Token::eEnumerator, (unsigned int)scope->enumeratorList[2].name->tokType()); + ASSERT_EQUALS_ENUM(Token::eEnumerator, scope->enumeratorList[2].name->tokType()); ASSERT(scope->enumeratorList[2].scope == &*scope); ASSERT_EQUALS("E3", scope->enumeratorList[2].name->str()); ASSERT(scope->enumeratorList[2].start != nullptr); @@ -8677,22 +8677,22 @@ class TestSymbolDatabase : public TestFixture { void valueTypeMatchParameter() const { ValueType vt_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0); ValueType vt_const_int(ValueType::Sign::SIGNED, ValueType::Type::INT, 0, 1); - ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_int)); - ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_const_int, &vt_int)); - ASSERT_EQUALS((int)ValueType::MatchResult::SAME, (int)ValueType::matchParameter(&vt_int, &vt_const_int)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::SAME, ValueType::matchParameter(&vt_int, &vt_int)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::SAME, ValueType::matchParameter(&vt_const_int, &vt_int)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::SAME, ValueType::matchParameter(&vt_int, &vt_const_int)); ValueType vt_char_pointer(ValueType::Sign::SIGNED, ValueType::Type::CHAR, 1); ValueType vt_void_pointer(ValueType::Sign::SIGNED, ValueType::Type::VOID, 1); // compatible ValueType vt_int_pointer(ValueType::Sign::SIGNED, ValueType::Type::INT, 1); // not compatible - ASSERT_EQUALS((int)ValueType::MatchResult::FALLBACK1, (int)ValueType::matchParameter(&vt_char_pointer, &vt_void_pointer)); - ASSERT_EQUALS((int)ValueType::MatchResult::NOMATCH, (int)ValueType::matchParameter(&vt_char_pointer, &vt_int_pointer)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::FALLBACK1, ValueType::matchParameter(&vt_char_pointer, &vt_void_pointer)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::NOMATCH, ValueType::matchParameter(&vt_char_pointer, &vt_int_pointer)); ValueType vt_char_pointer2(ValueType::Sign::SIGNED, ValueType::Type::CHAR, 2); - ASSERT_EQUALS((int)ValueType::MatchResult::FALLBACK1, (int)ValueType::matchParameter(&vt_char_pointer2, &vt_void_pointer)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::FALLBACK1, ValueType::matchParameter(&vt_char_pointer2, &vt_void_pointer)); ValueType vt_const_float_pointer(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::FLOAT, 1, 1); ValueType vt_long_long(ValueType::Sign::SIGNED, ValueType::Type::LONGLONG, 0, 0); - ASSERT_EQUALS((int)ValueType::MatchResult::NOMATCH, (int)ValueType::matchParameter(&vt_const_float_pointer, &vt_long_long)); + ASSERT_EQUALS_ENUM(ValueType::MatchResult::NOMATCH, ValueType::matchParameter(&vt_const_float_pointer, &vt_long_long)); } #define FUNC(x) do { \ diff --git a/test/testtimer.cpp b/test/testtimer.cpp index d9d3c0b690a..404fdf76829 100644 --- a/test/testtimer.cpp +++ b/test/testtimer.cpp @@ -34,7 +34,7 @@ class TestTimer : public TestFixture { void result() const { TimerResultsData t1; - t1.mClocks = ~(std::clock_t)0; + t1.mClocks = ~static_cast(0); ASSERT(t1.seconds() > 100.0); t1.mClocks = CLOCKS_PER_SEC * 5 / 2; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index b29f069ed56..05a9cfc1922 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -570,8 +570,8 @@ class TestValueFlow : public TestFixture { ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue); ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue); ASSERT_EQUALS(0, valueOfTok("x(NULL);", "NULL").intvalue); - ASSERT_EQUALS((int)('a'), valueOfTok("x='a';", "'a'").intvalue); - ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); + ASSERT_EQUALS(static_cast('a'), valueOfTok("x='a';", "'a'").intvalue); + ASSERT_EQUALS(static_cast('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); TODO_ASSERT_EQUALS(0xFFFFFFFF00000000, 0, valueOfTok("x=0xFFFFFFFF00000000;", "0xFFFFFFFF00000000").intvalue); // #7701 ASSERT_EQUALS_DOUBLE(16, valueOfTok("x=(double)16;", "(").floatValue, 1e-5); ASSERT_EQUALS_DOUBLE(0.0625, valueOfTok("x=1/(double)16;", "/").floatValue, 1e-5); @@ -934,7 +934,7 @@ class TestValueFlow : public TestFixture { " const char *x = \"abcd\";\n" " return x[0];\n" "}"; - ASSERT_EQUALS((int)('a'), valueOfTok(code, "[").intvalue); + ASSERT_EQUALS(static_cast('a'), valueOfTok(code, "[").intvalue); code = "char f() {\n" " const char *x = \"\";\n" @@ -3884,7 +3884,7 @@ class TestValueFlow : public TestFixture { " x += 67;\n" " return x;\n" "}"; - ASSERT_EQUALS(true, testValueOfX(code, 4U, (double)123.45f + 67, 0.01)); + ASSERT_EQUALS(true, testValueOfX(code, 4U, static_cast(123.45f) + 67, 0.01)); code = "double f() {\n" " double x = 123.45;\n"