Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed some modernize-use-auto clean-tidy warnings #4663

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/cppcheckexecutorsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const ucontext_t*>(context);
const auto* const uc = reinterpret_cast<const ucontext_t*>(context);
killid = (pid_t) syscall(SYS_gettid);
if (uc) {
type = (int)uc->uc_mcontext.gregs[REG_ERR] & 2;
Expand Down
4 changes: 2 additions & 2 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ namespace {
void writeToPipe(PipeSignal type, const std::string &data) const
{
{
const char t = static_cast<char>(type);
const auto t = static_cast<char>(type);
writeToPipeInternal(type, &t, 1);
}

const unsigned int len = static_cast<unsigned int>(data.length());
const auto len = static_cast<unsigned int>(data.length());
{
static constexpr std::size_t l_size = sizeof(unsigned int);
writeToPipeInternal(type, &len, l_size);
Expand Down
8 changes: 4 additions & 4 deletions gui/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
10 changes: 5 additions & 5 deletions gui/codeeditstyledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"),
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gui/librarydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()))
Expand Down
16 changes: 8 additions & 8 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -1634,7 +1634,7 @@ void MainWindow::openHelpContents()

void MainWindow::openOnlineHelp()
{
HelpDialog *helpDialog = new HelpDialog;
auto *helpDialog = new HelpDialog;
helpDialog->showMaximized();
}

Expand Down Expand Up @@ -1923,7 +1923,7 @@ void MainWindow::enableProjectOpenActions(bool enable)

void MainWindow::openRecentProject()
{
QAction *action = qobject_cast<QAction *>(sender());
auto *action = qobject_cast<QAction *>(sender());
if (!action)
return;
const QString project = action->data().toString();
Expand Down Expand Up @@ -2012,7 +2012,7 @@ void MainWindow::removeProjectMRU(const QString &project)

void MainWindow::selectPlatform()
{
QAction *action = qobject_cast<QAction *>(sender());
auto *action = qobject_cast<QAction *>(sender());
if (action) {
const Platform::Type platform = (Platform::Type) action->data().toInt();
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
Expand Down
10 changes: 5 additions & 5 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
26 changes: 13 additions & 13 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ 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;
}

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);
Expand All @@ -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);
Expand Down Expand Up @@ -611,15 +611,15 @@ 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
int defaultApplicationIndex = mApplications->getDefaultApplication();
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);

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -691,15 +691,15 @@ 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());
});
}

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);
Expand Down
2 changes: 1 addition & 1 deletion gui/resultsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void ResultsView::readErrorsXml(const QString &filename)

void ResultsView::updateDetails(const QModelIndex &index)
{
const QStandardItemModel *model = qobject_cast<const QStandardItemModel*>(mUI->mTree->model());
const auto *model = qobject_cast<const QStandardItemModel*>(mUI->mTree->model());
QStandardItem *item = model->itemFromIndex(index);

if (!item) {
Expand Down
2 changes: 1 addition & 1 deletion gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -384,30 +384,30 @@ 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);

for (QAbstractSeries *s : chart->series()) {
s->attachAxis(axisX);
}

QValueAxis *axisY = new QValueAxis;
auto *axisY = new QValueAxis;
axisY->setLabelFormat("%i");
axisY->setTitleText("Count");
chart->addAxis(axisY, Qt::AlignLeft);

qreal maxY = 0;
for (QAbstractSeries *s : chart->series()) {
s->attachAxis(axisY);
if (const QLineSeries *ls = dynamic_cast<const QLineSeries*>(s)) {
if (const auto *ls = dynamic_cast<const QLineSeries*>(s)) {
for (QPointF p : ls->points()) {
if (p.y() > maxY)
maxY = p.y();
Expand All @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down
Loading
Loading