diff --git a/cli/cppcheckexecutorsig.cpp b/cli/cppcheckexecutorsig.cpp index 279a95633..16300ac8e 100644 --- a/cli/cppcheckexecutorsig.cpp +++ b/cli/cppcheckexecutorsig.cpp @@ -109,7 +109,7 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context) pid_t killid; // TODO: separate these two defines #if defined(__linux__) && defined(REG_ERR) - const ucontext_t* const uc = reinterpret_cast(context); + const auto* const uc = reinterpret_cast(context); killid = (pid_t) syscall(SYS_gettid); if (uc) { type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2; diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index ae41d6117..9a514c66c 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -107,11 +107,11 @@ namespace { void writeToPipe(PipeSignal type, const std::string &data) const { { - const char t = static_cast(type); + const auto t = static_cast(type); writeToPipeInternal(type, &t, 1); } - const unsigned int len = static_cast(data.length()); + const auto len = static_cast(data.length()); { static constexpr std::size_t l_size = sizeof(unsigned int); writeToPipeInternal(type, &len, l_size); diff --git a/gui/codeeditor.cpp b/gui/codeeditor.cpp index a407bcdb5..0703f9aee 100644 --- a/gui/codeeditor.cpp +++ b/gui/codeeditor.cpp @@ -287,11 +287,11 @@ CodeEditor::CodeEditor(QWidget *parent) : setStyleSheet(generateStyleString()); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) - QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_C),this); - QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_A),this); + auto *copyText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_C),this); + auto *allText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_A),this); #else - const QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this); - const QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this); + const auto *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this); + const auto *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this); #endif connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); diff --git a/gui/codeeditstyledialog.cpp b/gui/codeeditstyledialog.cpp index dc2dd0ff1..42542af44 100644 --- a/gui/codeeditstyledialog.cpp +++ b/gui/codeeditstyledialog.cpp @@ -72,10 +72,10 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle, mStyleIncoming(newStyle), mStyleOutgoing(newStyle) { - QVBoxLayout *vboxMain = new QVBoxLayout(this); - QHBoxLayout *hboxEdit = new QHBoxLayout(); + auto *vboxMain = new QVBoxLayout(this); + auto *hboxEdit = new QHBoxLayout(); // Color/Weight controls - QFormLayout *flEditControls = new QFormLayout(); + auto *flEditControls = new QFormLayout(); mBtnWidgetColorFG = new SelectColorButton(this); flEditControls->addRow(QObject::tr("Editor Foreground Color"), mBtnWidgetColorFG); @@ -141,7 +141,7 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle, vboxMain->addLayout(hboxEdit); // Default Controls - QHBoxLayout *hboxDefaultControls = new QHBoxLayout(); + auto *hboxDefaultControls = new QHBoxLayout(); mBtnDefaultLight = new QPushButton(QObject::tr("Set to Default Light"), this); mBtnDefaultDark = new QPushButton(QObject::tr("Set to Default Dark"), @@ -153,7 +153,7 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle, vboxMain->addLayout(hboxDefaultControls); vboxMain->addStretch(2); // dialog controls - QDialogButtonBox *dBtnBox = new QDialogButtonBox( + auto *dBtnBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok | QDialogButtonBox::Reset); diff --git a/gui/librarydialog.cpp b/gui/librarydialog.cpp index e42417cbb..8ae362bd2 100644 --- a/gui/librarydialog.cpp +++ b/gui/librarydialog.cpp @@ -185,7 +185,7 @@ void LibraryDialog::saveCfgAs() void LibraryDialog::addFunction() { - LibraryAddFunctionDialog *d = new LibraryAddFunctionDialog; + auto *d = new LibraryAddFunctionDialog; if (d->exec() == QDialog::Accepted && !d->functionName().isEmpty()) { CppcheckLibraryData::Function f; diff --git a/gui/main.cpp b/gui/main.cpp index 989e85a55..191f3ba7e 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("Cppcheck"); QCoreApplication::setApplicationName("Cppcheck-GUI"); - QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app); + auto* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app); // Set data dir.. const QStringList args = QApplication::arguments(); @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) return 0; } - TranslationHandler* th = new TranslationHandler(&app); + auto* th = new TranslationHandler(&app); th->setLanguage(settings->value(SETTINGS_LANGUAGE, th->suggestLanguage()).toString()); if (!CheckArgs(QApplication::arguments())) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 584b177ef..323f02558 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -247,7 +247,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : for (int i = 0; i < mPlatforms.getCount(); i++) { PlatformData platform = mPlatforms.mPlatforms[i]; - QAction *action = new QAction(this); + auto *action = new QAction(this); platform.mActMainWindow = action; mPlatforms.mPlatforms[i] = platform; action->setText(platform.mTitle); @@ -1021,7 +1021,7 @@ Settings MainWindow::getCppcheckSettings() result.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString()); } else { for (int i = Platform::Type::Native; i <= Platform::Type::Unix64; i++) { - const Platform::Type p = (Platform::Type)i; + const auto p = (Platform::Type)i; if (platform == Platform::toString(p)) { result.platform.set(p); break; @@ -1468,21 +1468,21 @@ void MainWindow::about() msg.exec(); } else { - AboutDialog *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), this); + auto *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), this); dlg->exec(); } } void MainWindow::showLicense() { - FileViewDialog *dlg = new FileViewDialog(":COPYING", tr("License"), this); + auto *dlg = new FileViewDialog(":COPYING", tr("License"), this); dlg->resize(570, 400); dlg->exec(); } void MainWindow::showAuthors() { - FileViewDialog *dlg = new FileViewDialog(":AUTHORS", tr("Authors"), this); + auto *dlg = new FileViewDialog(":AUTHORS", tr("Authors"), this); dlg->resize(350, 400); dlg->exec(); } @@ -1634,7 +1634,7 @@ void MainWindow::openHelpContents() void MainWindow::openOnlineHelp() { - HelpDialog *helpDialog = new HelpDialog; + auto *helpDialog = new HelpDialog; helpDialog->showMaximized(); } @@ -1923,7 +1923,7 @@ void MainWindow::enableProjectOpenActions(bool enable) void MainWindow::openRecentProject() { - QAction *action = qobject_cast(sender()); + auto *action = qobject_cast(sender()); if (!action) return; const QString project = action->data().toString(); @@ -2012,7 +2012,7 @@ void MainWindow::removeProjectMRU(const QString &project) void MainWindow::selectPlatform() { - QAction *action = qobject_cast(sender()); + auto *action = qobject_cast(sender()); if (action) { const Platform::Type platform = (Platform::Type) action->data().toInt(); mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform); diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index ecf2d3408..b30534393 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -182,7 +182,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi libs.sort(); mUI->mLibraries->clear(); for (const QString &lib : libs) { - QListWidgetItem* item = new QListWidgetItem(lib, mUI->mLibraries); + auto* item = new QListWidgetItem(lib, mUI->mLibraries); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag item->setCheckState(Qt::Unchecked); // AND initialize check state } @@ -604,7 +604,7 @@ void ProjectFileDialog::setProjectConfigurations(const QStringList &configs) mUI->mListVsConfigs->clear(); mUI->mListVsConfigs->setEnabled(!configs.isEmpty() && !mUI->mChkAllVsConfigs->isChecked()); for (const QString &cfg : configs) { - QListWidgetItem* item = new QListWidgetItem(cfg, mUI->mListVsConfigs); + auto* item = new QListWidgetItem(cfg, mUI->mListVsConfigs); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag item->setCheckState(Qt::Unchecked); } @@ -621,7 +621,7 @@ void ProjectFileDialog::addIncludeDir(const QString &dir) return; const QString newdir = QDir::toNativeSeparators(dir); - QListWidgetItem *item = new QListWidgetItem(newdir); + auto *item = new QListWidgetItem(newdir); item->setFlags(item->flags() | Qt::ItemIsEditable); mUI->mListIncludeDirs->addItem(item); } @@ -632,7 +632,7 @@ void ProjectFileDialog::addCheckPath(const QString &path) return; const QString newpath = QDir::toNativeSeparators(path); - QListWidgetItem *item = new QListWidgetItem(newpath); + auto *item = new QListWidgetItem(newpath); item->setFlags(item->flags() | Qt::ItemIsEditable); mUI->mListCheckPaths->addItem(item); } @@ -643,7 +643,7 @@ void ProjectFileDialog::addExcludePath(const QString &path) return; const QString newpath = QDir::toNativeSeparators(path); - QListWidgetItem *item = new QListWidgetItem(newpath); + auto *item = new QListWidgetItem(newpath); item->setFlags(item->flags() | Qt::ItemIsEditable); mUI->mListExcludedPaths->addItem(item); } diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index ec1777ad5..66dbbd676 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -110,7 +110,7 @@ void ResultsTree::initialize(QSettings *settings, ApplicationList *list, ThreadH QStandardItem *ResultsTree::createNormalItem(const QString &name) { - QStandardItem *item = new QStandardItem(name); + auto *item = new QStandardItem(name); item->setData(name, Qt::ToolTipRole); item->setEditable(false); return item; @@ -118,7 +118,7 @@ QStandardItem *ResultsTree::createNormalItem(const QString &name) QStandardItem *ResultsTree::createCheckboxItem(bool checked) { - QStandardItem *item = new QStandardItem; + auto *item = new QStandardItem; item->setCheckable(true); item->setCheckState(checked ? Qt::Checked : Qt::Unchecked); item->setEnabled(false); @@ -127,7 +127,7 @@ QStandardItem *ResultsTree::createCheckboxItem(bool checked) QStandardItem *ResultsTree::createLineNumberItem(const QString &linenumber) { - QStandardItem *item = new QStandardItem(); + auto *item = new QStandardItem(); item->setData(QVariant(linenumber.toInt()), Qt::DisplayRole); item->setToolTip(linenumber); item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); @@ -611,7 +611,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) //Create a signal mapper so we don't have to store data to class //member variables - QSignalMapper *signalMapper = new QSignalMapper(this); + auto *signalMapper = new QSignalMapper(this); if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) { //Create an action for the application @@ -619,7 +619,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) if (defaultApplicationIndex < 0) defaultApplicationIndex = 0; const Application& app = mApplications->getApplication(defaultApplicationIndex); - QAction *start = new QAction(app.getName(), &menu); + auto *start = new QAction(app.getName(), &menu); if (multipleSelection) start->setDisabled(true); @@ -646,11 +646,11 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) } //Create an action for the application - QAction *recheckAction = new QAction(tr("Recheck"), &menu); - QAction *copyAction = new QAction(tr("Copy"), &menu); - QAction *hide = new QAction(tr("Hide"), &menu); - QAction *hideallid = new QAction(tr("Hide all with id"), &menu); - QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); + auto *recheckAction = new QAction(tr("Recheck"), &menu); + auto *copyAction = new QAction(tr("Copy"), &menu); + auto *hide = new QAction(tr("Hide"), &menu); + auto *hideallid = new QAction(tr("Hide all with id"), &menu); + auto *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); if (multipleSelection) { hideallid->setDisabled(true); @@ -668,7 +668,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) menu.addAction(hide); menu.addAction(hideallid); - QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu); + auto *suppress = new QAction(tr("Suppress selected id(s)"), &menu); { QVariantMap data = mContextItem->data().toMap(); const QString messageId = data[ERRORID].toString(); @@ -691,7 +691,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) menu.addSeparator(); QMenu *tagMenu = menu.addMenu(tr("Tag")); { - QAction *action = new QAction(tr("No tag"), tagMenu); + auto *action = new QAction(tr("No tag"), tagMenu); tagMenu->addAction(action); connect(action, &QAction::triggered, [=]() { tagSelectedItems(QString()); @@ -699,7 +699,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) } for (const QString& tagstr : currentProject->getTags()) { - QAction *action = new QAction(tagstr, tagMenu); + auto *action = new QAction(tagstr, tagMenu); tagMenu->addAction(action); connect(action, &QAction::triggered, [=]() { tagSelectedItems(tagstr); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 489d6d3aa..a8bf09c42 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -436,7 +436,7 @@ void ResultsView::readErrorsXml(const QString &filename) void ResultsView::updateDetails(const QModelIndex &index) { - const QStandardItemModel *model = qobject_cast(mUI->mTree->model()); + const auto *model = qobject_cast(mUI->mTree->model()); QStandardItem *item = model->itemFromIndex(index); if (!item) { diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 8acf493da..7144f3793 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -140,7 +140,7 @@ void SettingsDialog::initTranslationsList() { const QString current = mTranslator->getCurrentLanguage(); for (const TranslationInfo& translation : mTranslator->getTranslations()) { - QListWidgetItem *item = new QListWidgetItem; + auto *item = new QListWidgetItem; item->setText(translation.mName); item->setData(mLangCodeRole, QVariant(translation.mCode)); mUI->mListLanguages->addItem(item); diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 4d21a0338..e61664f3d 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -362,7 +362,7 @@ void StatsDialog::copyToClipboard() const QString htmlSummary = htmlSettings + htmlPrevious + htmlStatistics; - QMimeData *mimeData = new QMimeData(); + auto *mimeData = new QMimeData(); mimeData->setText(textSummary); mimeData->setHtml(htmlSummary); clipboard->setMimeData(mimeData); @@ -384,14 +384,14 @@ void StatsDialog::setStatistics(const CheckStatistics *stats) #ifdef QT_CHARTS_LIB QChartView *createChart(const QString &statsFile, const QString &tool) { - QChart *chart = new QChart; + auto *chart = new QChart; chart->addSeries(numberOfReports(statsFile, tool + "-error")); chart->addSeries(numberOfReports(statsFile, tool + "-warning")); chart->addSeries(numberOfReports(statsFile, tool + "-style")); chart->addSeries(numberOfReports(statsFile, tool + "-performance")); chart->addSeries(numberOfReports(statsFile, tool + "-portability")); - QDateTimeAxis *axisX = new QDateTimeAxis; + auto *axisX = new QDateTimeAxis; axisX->setTitleText("Date"); chart->addAxis(axisX, Qt::AlignBottom); @@ -399,7 +399,7 @@ QChartView *createChart(const QString &statsFile, const QString &tool) s->attachAxis(axisX); } - QValueAxis *axisY = new QValueAxis; + auto *axisY = new QValueAxis; axisY->setLabelFormat("%i"); axisY->setTitleText("Count"); chart->addAxis(axisY, Qt::AlignLeft); @@ -407,7 +407,7 @@ QChartView *createChart(const QString &statsFile, const QString &tool) qreal maxY = 0; for (QAbstractSeries *s : chart->series()) { s->attachAxis(axisY); - if (const QLineSeries *ls = dynamic_cast(s)) { + if (const auto *ls = dynamic_cast(s)) { for (QPointF p : ls->points()) { if (p.y() > maxY) maxY = p.y(); @@ -419,14 +419,14 @@ QChartView *createChart(const QString &statsFile, const QString &tool) //chart->createDefaultAxes(); chart->setTitle(tool); - QChartView *chartView = new QChartView(chart); + auto *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); return chartView; } QLineSeries *numberOfReports(const QString &fileName, const QString &severity) { - QLineSeries *series = new QLineSeries(); + auto *series = new QLineSeries(); series->setName(severity); QFile f(fileName); if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index dea22b984..16bced305 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -948,7 +948,7 @@ bool CheckBufferOverrun::isCtuUnsafePointerArith(const Settings *settings, const /** @brief Parse current TU and extract file info */ Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const { - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; fileInfo->unsafeArrayIndex = CTU::getUnsafeUsage(tokenizer, settings, isCtuUnsafeArrayIndex); fileInfo->unsafePointerArith = CTU::getUnsafeUsage(tokenizer, settings, isCtuUnsafePointerArith); if (fileInfo->unsafeArrayIndex.empty() && fileInfo->unsafePointerArith.empty()) { @@ -964,7 +964,7 @@ Check::FileInfo * CheckBufferOverrun::loadFileInfoFromXml(const tinyxml2::XMLEle const std::string arrayIndex("array-index"); const std::string pointerArith("pointer-arith"); - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) { if (e->Name() == arrayIndex) fileInfo->unsafeArrayIndex = CTU::loadUnsafeUsageListFromXml(e); diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 37a345a93..ec3a9521b 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3510,14 +3510,14 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti if (classDefinitions.empty()) return nullptr; - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; fileInfo->classDefinitions.swap(classDefinitions); return fileInfo; } Check::FileInfo * CheckClass::loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const { - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; for (const tinyxml2::XMLElement *e = xmlElement->FirstChildElement(); e; e = e->NextSiblingElement()) { if (std::strcmp(e->Name(), "class") != 0) continue; diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 660cc1ab5..e3f69a0c2 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -1285,15 +1285,15 @@ void CheckCondition::checkIncorrectLogicOperator() // 5 => testvalue is larger than both value1 and value2 bool result1, result2; if (isfloat) { - const double testvalue = getvalue(test, d1, d2); + const auto testvalue = getvalue(test, d1, d2); result1 = checkFloatRelation(op1, testvalue, d1); result2 = checkFloatRelation(op2, testvalue, d2); } else if (useUnsignedInt) { - const MathLib::biguint testvalue = getvalue(test, u1, u2); + const auto testvalue = getvalue(test, u1, u2); result1 = checkIntRelation(op1, testvalue, u1); result2 = checkIntRelation(op2, testvalue, u2); } else { - const MathLib::bigint testvalue = getvalue(test, i1, i2); + const auto testvalue = getvalue(test, i1, i2); result1 = checkIntRelation(op1, testvalue, i1); result2 = checkIntRelation(op2, testvalue, i2); } diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index bb530e63a..cec36ee06 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -586,7 +586,7 @@ Check::FileInfo *CheckNullPointer::getFileInfo(const Tokenizer *tokenizer, const if (unsafeUsage.empty()) return nullptr; - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; fileInfo->unsafeUsage = unsafeUsage; return fileInfo; } @@ -597,7 +597,7 @@ Check::FileInfo * CheckNullPointer::loadFileInfoFromXml(const tinyxml2::XMLEleme if (unsafeUsage.empty()) return nullptr; - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; fileInfo->unsafeUsage = unsafeUsage; return fileInfo; } diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f797c1897..7fa7c1c76 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1705,7 +1705,7 @@ Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer *tokenizer, const S if (unsafeUsage.empty()) return nullptr; - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; fileInfo->unsafeUsage = unsafeUsage; return fileInfo; } @@ -1716,7 +1716,7 @@ Check::FileInfo * CheckUninitVar::loadFileInfoFromXml(const tinyxml2::XMLElement if (unsafeUsage.empty()) return nullptr; - MyFileInfo *fileInfo = new MyFileInfo; + auto *fileInfo = new MyFileInfo; fileInfo->unsafeUsage = unsafeUsage; return fileInfo; } diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index a0d2bba55..a31956e68 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -648,7 +648,7 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType { SymbolDatabase *symbolDatabase = mData->mSymbolDatabase; - Scope *nestedIn = const_cast(getNestedInScope(tokenList)); + auto *nestedIn = const_cast(getNestedInScope(tokenList)); symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nestedIn); Scope *scope = &symbolDatabase->scopeList.back(); @@ -974,7 +974,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == EnumConstantDecl) { Token *nameToken = addtoken(tokenList, getSpelling()); - Scope *scope = const_cast(nameToken->scope()); + auto *scope = const_cast(nameToken->scope()); scope->enumeratorList.emplace_back(nameToken->scope()); Enumerator *e = &scope->enumeratorList.back(); e->name = nameToken; @@ -1326,7 +1326,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList) addFullScopeNameTokens(tokenList, mData->getScope(mExtTokens[2])); Token *nameToken = addtoken(tokenList, getSpelling() + getTemplateParameters()); - Scope *nestedIn = const_cast(nameToken->scope()); + auto *nestedIn = const_cast(nameToken->scope()); if (prev) { const std::string addr = *(std::find(mExtTokens.cbegin(), mExtTokens.cend(), "prev") + 1); @@ -1343,7 +1343,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList) nestedIn->functionList.back().retDef = startToken; } - Function * const function = const_cast(nameToken->function()); + auto * const function = const_cast(nameToken->function()); if (!prev) { auto accessControl = mData->scopeAccessControl.find(tokenList->back()->scope()); @@ -1486,7 +1486,7 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList) else if (startToken->str() != "static") startToken = startToken->next(); Token *vartok1 = addtoken(tokenList, name); - Scope *scope = const_cast(tokenList->back()->scope()); + auto *scope = const_cast(tokenList->back()->scope()); scope->varlist.emplace_back(vartok1, unquote(type), startToken, vartok1->previous(), 0, scope->defaultAccess(), recordType, scope); mData->varDecl(addr, vartok1, &scope->varlist.back()); if (mExtTokens.back() == "cinit" && !children.empty()) { @@ -1542,7 +1542,7 @@ static void setValues(const Tokenizer *tokenizer, const SymbolDatabase *symbolDa scope.definedType->sizeOf = typeSize; } - for (Token *tok = const_cast(tokenizer->tokens()); tok; tok = tok->next()) { + for (auto *tok = const_cast(tokenizer->tokens()); tok; tok = tok->next()) { if (Token::simpleMatch(tok, "sizeof (")) { ValueType vt = ValueType::parseDecl(tok->tokAt(2), *settings); const int sz = vt.typeSize(settings->platform, true); @@ -1568,7 +1568,7 @@ void clangimport::parseClangAstDump(Tokenizer *tokenizer, std::istream &f) TokenList *tokenList = &tokenizer->list; tokenizer->createSymbolDatabase(); - SymbolDatabase *symbolDatabase = const_cast(tokenizer->getSymbolDatabase()); + auto *symbolDatabase = const_cast(tokenizer->getSymbolDatabase()); symbolDatabase->scopeList.emplace_back(nullptr, nullptr, nullptr); symbolDatabase->scopeList.back().type = Scope::ScopeType::eGlobal; symbolDatabase->scopeList.back().check = symbolDatabase; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9f912697d..b77eb7edc 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1347,8 +1347,8 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token } break; } - const unsigned int pos1 = (unsigned int)ovector[0]; - const unsigned int pos2 = (unsigned int)ovector[1]; + const auto pos1 = (unsigned int)ovector[0]; + const auto pos2 = (unsigned int)ovector[1]; // jump to the end of the match for the next pcre_exec pos = (int)pos2; @@ -1751,7 +1751,7 @@ bool CppCheck::analyseWholeProgram() // Analyse the tokens CTU::FileInfo ctu; for (const Check::FileInfo *fi : mFileInfo) { - const CTU::FileInfo *fi2 = dynamic_cast(fi); + const auto *fi2 = dynamic_cast(fi); if (fi2) { ctu.functionCalls.insert(ctu.functionCalls.end(), fi2->functionCalls.cbegin(), fi2->functionCalls.cend()); ctu.nestedCalls.insert(ctu.nestedCalls.end(), fi2->nestedCalls.cbegin(), fi2->nestedCalls.cend()); diff --git a/lib/ctu.cpp b/lib/ctu.cpp index 004ed4bcc..cc40a841f 100644 --- a/lib/ctu.cpp +++ b/lib/ctu.cpp @@ -309,7 +309,7 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer) { const SymbolDatabase * const symbolDatabase = tokenizer->getSymbolDatabase(); - FileInfo *fileInfo = new FileInfo; + auto *fileInfo = new FileInfo; // Parse all functions in TU for (const Scope &scope : symbolDatabase->scopeList) { @@ -513,7 +513,7 @@ static bool findPath(const std::string &callId, if (c->callArgNr != callArgNr) continue; - const CTU::FileInfo::FunctionCall *functionCall = dynamic_cast(c); + const auto *functionCall = dynamic_cast(c); if (functionCall) { if (!warning && functionCall->warning) continue; @@ -537,7 +537,7 @@ static bool findPath(const std::string &callId, return true; } - const CTU::FileInfo::NestedCall *nestedCall = dynamic_cast(c); + const auto *nestedCall = dynamic_cast(c); if (!nestedCall) continue; @@ -570,7 +570,7 @@ std::list CTU::FileInfo::getErrorPath(InvalidValueTy if (!path[index]) continue; - const CTU::FileInfo::FunctionCall *functionCall = dynamic_cast(path[index]); + const auto *functionCall = dynamic_cast(path[index]); if (functionCall) { if (functionCallPtr) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 05b89ed61..be63697ec 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1052,7 +1052,7 @@ void SymbolDatabase::createSymbolDatabaseSetScopePointers() const_cast(bodyEnd)->scope(&scope); - for (Token* tok = const_cast(bodyStart); tok != bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(bodyStart); tok != bodyEnd; tok = tok->next()) { if (bodyStart != bodyEnd && tok->str() == "{") { bool isEndOfScope = false; for (Scope* innerScope: scope.nestedList) { @@ -1702,7 +1702,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() std::unordered_map unknownIds; // Assign IDs to incomplete vars which are part of an expression // Such variables should be assumed global - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (!tok->isIncompleteVar()) continue; if (!isExpression(tok->astParent())) @@ -1725,7 +1725,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() // Assign IDs ExprIdMap exprIdMap; std::map baseIds; - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (tok->varId() > 0) { tok->exprId(tok->varId()); if (tok->astParent() && tok->astParent()->exprId() == 0) @@ -1794,7 +1794,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() continue; // check each array dimension for (const Dimension &const_dimension : var->dimensions()) { - Dimension &dimension = const_cast(const_dimension); + auto &dimension = const_cast(const_dimension); if (dimension.num != 0 || !dimension.tok) continue; @@ -3383,7 +3383,7 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To if (match) { auto range = scope1->functionMap.equal_range((*tok)->str()); for (std::multimap::const_iterator it = range.first; it != range.second; ++it) { - Function * func = const_cast(it->second); + auto * func = const_cast(it->second); if (!func->hasBody()) { if (func->argsMatch(scope1, func->argDef, (*tok)->next(), path, path_length)) { const Token *closeParen = (*tok)->next()->link(); @@ -6502,7 +6502,7 @@ static bool isContainerYieldPointer(Library::Container::Yield yield) void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, SourceLocation loc) { - ValueType* valuetypePtr = new ValueType(valuetype); + auto* valuetypePtr = new ValueType(valuetype); if (mSettings.debugnormal || mSettings.debugwarnings) valuetypePtr->setDebugPath(tok, loc); tok->setValueType(valuetypePtr); @@ -6584,7 +6584,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source setValueType(var1Tok, vt); if (var1Tok != parent->previous()) setValueType(parent->previous(), vt); - Variable *var = const_cast(parent->previous()->variable()); + auto *var = const_cast(parent->previous()->variable()); if (var) { ValueType vt2_(*vt2); if (vt2_.pointer == 0 && autoTok->strAt(1) == "*") @@ -6737,7 +6737,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source varvt.constness |= 1; } setValueType(parent->previous(), varvt); - Variable *var = const_cast(parent->previous()->variable()); + auto *var = const_cast(parent->previous()->variable()); if (var) { var->setValueType(varvt); if (vt2->typeScope && vt2->typeScope->definedType) { @@ -6803,7 +6803,7 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source if (isconst) varvt.constness |= (1 << autovt.pointer); setValueType(parent->previous(), varvt); - Variable * var = const_cast(parent->previous()->variable()); + auto * var = const_cast(parent->previous()->variable()); if (var) { var->setValueType(varvt); if (templateArgType && templateArgType->classScope && templateArgType->classScope->definedType) { diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 86a10d5a7..b7e0b318b 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1376,7 +1376,7 @@ void TemplateSimplifier::simplifyTemplateAliases() } if (found) { - Token *end = const_cast(aliasDeclaration.aliasEndToken()); + auto *end = const_cast(aliasDeclaration.aliasEndToken()); // remove declaration tokens if (aliasDeclaration.token()->previous()) @@ -3227,7 +3227,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( // process uninstantiated templates // TODO: remove the specialized check and handle all uninstantiated templates someday. if (!instantiated && specialized) { - Token * tok2 = const_cast(templateDeclaration.nameToken()); + auto * tok2 = const_cast(templateDeclaration.nameToken()); if (mErrorLogger && !mTokenList.getFiles().empty()) mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue()); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2d82e02cd..6654006e6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3915,7 +3915,7 @@ void Tokenizer::simplifyLabelsCaseDefault() int indentLevel = 0; for (Token *tok = list.front(); tok; tok = tok->next()) { // Simplify labels in the executable scope.. - Token *start = const_cast(startOfExecutableScope(tok)); + auto *start = const_cast(startOfExecutableScope(tok)); if (start) { tok = start; executablescope = true; diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 8f1088fc7..63d538dd3 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5120,7 +5120,7 @@ static void valueFlowAfterMove(TokenList& tokenlist, const SymbolDatabase& symbo start = memberInitializationTok; } - for (Token* tok = const_cast(start); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(start); tok != scope->bodyEnd; tok = tok->next()) { Token * varTok; if (Token::Match(tok, "%var% . reset|clear (") && tok->next()->originalName().empty()) { varTok = tok; @@ -5376,7 +5376,7 @@ static std::set getVarIds(const Token* tok) static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, const Settings* settings) { for (const Scope* scope : symboldatabase.functionScopes) { - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "=")) continue; if (tok->astParent()) @@ -5469,7 +5469,7 @@ static ValueFlow::Value inferCondition(const std::string& op, const Token* varTo static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, const Settings* settings) { for (const Scope* scope : symboldatabase.functionScopes) { - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (tok->hasKnownIntValue()) continue; @@ -5582,7 +5582,7 @@ struct SymbolicInferModel : InferModel { static void valueFlowSymbolicInfer(const SymbolDatabase& symboldatabase, const Settings* settings) { for (const Scope* scope : symboldatabase.functionScopes) { - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::Match(tok, "-|%comp%")) continue; if (tok->hasKnownIntValue()) @@ -5930,7 +5930,7 @@ static void valueFlowAfterAssign(TokenList &tokenlist, if (skippedFunctions.count(scope)) continue; std::unordered_map> backAssigns; - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { // Assignment bool isInit = false; if (tok->str() != "=" && !(isInit = isVariableInit(tok))) @@ -6063,7 +6063,7 @@ static void valueFlowAfterSwap(TokenList& tokenlist, const Settings* settings) { for (const Scope* scope : symboldatabase.functionScopes) { - for (Token* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (!Token::simpleMatch(tok, "swap (")) continue; if (!Token::simpleMatch(tok->next()->astOperand2(), ",")) @@ -6238,7 +6238,7 @@ struct ConditionHandler { for (const Scope *scope : symboldatabase.functionScopes) { if (skippedFunctions.count(scope)) continue; - for (Token *tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { + for (auto *tok = const_cast(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "if|while|for (")) continue; if (Token::Match(tok, ":|;|,")) @@ -6727,7 +6727,7 @@ struct ConditionHandler { return; if (r.action.isModified()) return; - Token* start = const_cast(loopScope->bodyEnd); + auto* start = const_cast(loopScope->bodyEnd); if (Token::simpleMatch(start, "} while (")) { start = start->tokAt(2); forward(start, start->link(), cond.vartok, values, tokenlist, settings); @@ -7180,8 +7180,8 @@ static void valueFlowForLoop(TokenList &tokenlist, const SymbolDatabase& symbold if (scope.type != Scope::eFor) continue; - Token* tok = const_cast(scope.classDef); - Token* const bodyStart = const_cast(scope.bodyStart); + auto* tok = const_cast(scope.classDef); + auto* const bodyStart = const_cast(scope.bodyStart); if (!Token::simpleMatch(tok->next()->astOperand2(), ";") || !Token::simpleMatch(tok->next()->astOperand2()->astOperand2(), ";")) @@ -8779,7 +8779,7 @@ static void valueFlowContainerSize(TokenList& tokenlist, // after assignment for (const Scope *functionScope : symboldatabase.functionScopes) { - for (Token* tok = const_cast(functionScope->bodyStart); tok != functionScope->bodyEnd; tok = tok->next()) { + for (auto* tok = const_cast(functionScope->bodyStart); tok != functionScope->bodyEnd; tok = tok->next()) { if (Token::Match(tok, "%name%|;|{|} %var% = %str% ;")) { Token* containerTok = tok->next(); if (containerTok->exprId() == 0) diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 827f6f20c..213c9fd12 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -114,7 +114,7 @@ private: } void nextprevious() const { - Token *token = new Token(); + auto *token = new Token(); token->str("1"); token->insertToken("2"); token->next()->insertToken("3");