Skip to content

Commit cff1cd9

Browse files
authored
applied clang-tidy misc-const-correctness fixes for POD types, iterators and references (danmar#4529)
* applied `misc-const-correctness` fixes for POD types and iterators * applied `misc-const-correctness` fixes for references
1 parent 586c29c commit cff1cd9

56 files changed

Lines changed: 313 additions & 313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/filelister.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
218218
new_path = path + '/' + dir_result->d_name;
219219

220220
#if defined(_DIRENT_HAVE_D_TYPE) || defined(_BSD_SOURCE)
221-
bool path_is_directory = (dir_result->d_type == DT_DIR || (dir_result->d_type == DT_UNKNOWN && FileLister::isDirectory(new_path)));
221+
const bool path_is_directory = (dir_result->d_type == DT_DIR || (dir_result->d_type == DT_UNKNOWN && FileLister::isDirectory(new_path)));
222222
#else
223-
bool path_is_directory = FileLister::isDirectory(new_path);
223+
const bool path_is_directory = FileLister::isDirectory(new_path);
224224
#endif
225225
if (path_is_directory) {
226226
if (recursive && !ignored.match(new_path)) {

cli/processexecutor.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ unsigned int ProcessExecutor::check()
230230
std::list<ImportProject::FileSettings>::const_iterator iFileSettings = mSettings.project.fileSettings.begin();
231231
for (;;) {
232232
// Start a new child
233-
size_t nchildren = childFile.size();
233+
const size_t nchildren = childFile.size();
234234
if ((iFile != mFiles.end() || iFileSettings != mSettings.project.fileSettings.end()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
235235
int pipes[2];
236236
if (pipe(pipes) == -1) {
237237
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
238238
std::exit(EXIT_FAILURE);
239239
}
240240

241-
int flags = fcntl(pipes[0], F_GETFL, 0);
241+
const int flags = fcntl(pipes[0], F_GETFL, 0);
242242
if (flags < 0) {
243243
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
244244
std::exit(EXIT_FAILURE);
@@ -249,7 +249,7 @@ unsigned int ProcessExecutor::check()
249249
std::exit(EXIT_FAILURE);
250250
}
251251

252-
pid_t pid = fork();
252+
const pid_t pid = fork();
253253
if (pid < 0) {
254254
// Error
255255
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
@@ -298,20 +298,20 @@ unsigned int ProcessExecutor::check()
298298
struct timeval tv; // for every second polling of load average condition
299299
tv.tv_sec = 1;
300300
tv.tv_usec = 0;
301-
int r = select(*std::max_element(rpipes.begin(), rpipes.end()) + 1, &rfds, nullptr, nullptr, &tv);
301+
const int r = select(*std::max_element(rpipes.begin(), rpipes.end()) + 1, &rfds, nullptr, nullptr, &tv);
302302

303303
if (r > 0) {
304304
std::list<int>::iterator rp = rpipes.begin();
305305
while (rp != rpipes.end()) {
306306
if (FD_ISSET(*rp, &rfds)) {
307-
int readRes = handleRead(*rp, result);
307+
const int readRes = handleRead(*rp, result);
308308
if (readRes == -1) {
309309
std::size_t size = 0;
310-
std::map<int, std::string>::iterator p = pipeFile.find(*rp);
310+
const std::map<int, std::string>::iterator p = pipeFile.find(*rp);
311311
if (p != pipeFile.end()) {
312312
std::string name = p->second;
313313
pipeFile.erase(p);
314-
std::map<std::string, std::size_t>::const_iterator fs = mFiles.find(name);
314+
const std::map<std::string, std::size_t>::const_iterator fs = mFiles.find(name);
315315
if (fs != mFiles.end()) {
316316
size = fs->second;
317317
}
@@ -333,10 +333,10 @@ unsigned int ProcessExecutor::check()
333333
}
334334
if (!childFile.empty()) {
335335
int stat = 0;
336-
pid_t child = waitpid(0, &stat, WNOHANG);
336+
const pid_t child = waitpid(0, &stat, WNOHANG);
337337
if (child > 0) {
338338
std::string childname;
339-
std::map<pid_t, std::string>::iterator c = childFile.find(child);
339+
const std::map<pid_t, std::string>::iterator c = childFile.find(child);
340340
if (c != childFile.end()) {
341341
childname = c->second;
342342
childFile.erase(c);

gui/codeeditor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void Highlighter::highlightBlock(const QString &text)
217217

218218
while (startIndex >= 0) {
219219
QRegularExpressionMatch match = mCommentEndExpression.match(text, startIndex);
220-
int endIndex = match.capturedStart();
220+
const int endIndex = match.capturedStart();
221221
int commentLength = 0;
222222
if (endIndex == -1) {
223223
setCurrentBlockState(1);
@@ -353,9 +353,9 @@ int CodeEditor::lineNumberAreaWidth()
353353
}
354354

355355
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
356-
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
356+
const int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
357357
#else
358-
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
358+
const int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
359359
#endif
360360
return space;
361361
}

gui/codeeditorstyle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ void CodeEditorStyle::saveSettings(QSettings *settings,
183183
}
184184

185185
settings->beginGroup(SETTINGS_STYLE_GROUP);
186-
bool isDefaultLight = (defaultStyleLight == theStyle);
187-
bool isDefaultDark = (defaultStyleDark == theStyle);
186+
const bool isDefaultLight = (defaultStyleLight == theStyle);
187+
const bool isDefaultDark = (defaultStyleDark == theStyle);
188188
if (isDefaultLight && !isDefaultDark) {
189189
settings->setValue(SETTINGS_STYLE_TYPE,
190190
SETTINGS_STYLE_TYPE_LIGHT);

gui/codeeditstylecontrols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void SelectColorButton::changeColor()
4747
{
4848
QColorDialog pDlg(mColor);
4949
pDlg.setModal(true);
50-
int nResult = pDlg.exec();
50+
const int nResult = pDlg.exec();
5151
if (nResult == QDialog::Accepted) {
5252
setColor(pDlg.selectedColor());
5353
emit colorChanged(mColor);
@@ -95,7 +95,7 @@ SelectFontWeightCombo::SelectFontWeightCombo(QWidget* parent) :
9595

9696
void SelectFontWeightCombo::updateWeight()
9797
{
98-
int nResult = findData(QVariant(static_cast<int>(mWeight)));
98+
const int nResult = findData(QVariant(static_cast<int>(mWeight)));
9999

100100
if (nResult != -1) {
101101
setCurrentIndex(nResult);

gui/librarydialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void LibraryDialog::addFunction()
179179

180180
CppcheckLibraryData::Function f;
181181
f.name = d->functionName();
182-
int args = d->numberOfArguments();
182+
const int args = d->numberOfArguments();
183183

184184
for (int i = 1; i <= args; i++) {
185185
CppcheckLibraryData::Function::Arg arg;
@@ -321,7 +321,7 @@ void LibraryDialog::editArg()
321321

322322
LibraryEditArgDialog d(nullptr, arg);
323323
if (d.exec() == QDialog::Accepted) {
324-
unsigned number = arg.nr;
324+
const unsigned number = arg.nr;
325325
arg = d.getArg();
326326
arg.nr = number;
327327
mUi->arguments->selectedItems().first()->setText(getArgText(arg));

gui/mainwindow.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,15 @@ void MainWindow::loadSettings()
331331
mUI->mActionToolBarFilter->setChecked(showFilterToolbar);
332332
mUI->mToolBarFilter->setVisible(showFilterToolbar);
333333

334-
Settings::Language enforcedLanguage = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
334+
const Settings::Language enforcedLanguage = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
335335
if (enforcedLanguage == Settings::CPP)
336336
mUI->mActionEnforceCpp->setChecked(true);
337337
else if (enforcedLanguage == Settings::C)
338338
mUI->mActionEnforceC->setChecked(true);
339339
else
340340
mUI->mActionAutoDetectLanguage->setChecked(true);
341341

342-
bool succeeded = mApplications->loadSettings();
342+
const bool succeeded = mApplications->loadSettings();
343343
if (!succeeded) {
344344
const QString msg = tr("There was a problem with loading the editor application settings.\n\n"
345345
"This is probably because the settings were changed between the Cppcheck versions. "
@@ -436,7 +436,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
436436
p.ignorePaths(v);
437437

438438
if (!mProjectFile->getAnalyzeAllVsConfigs()) {
439-
Settings::PlatformType platform = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
439+
const Settings::PlatformType platform = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
440440
p.selectOneVsConfig(platform);
441441
}
442442
} else {
@@ -689,7 +689,7 @@ void MainWindow::analyzeDirectory()
689689
msgBox.addButton(QMessageBox::Yes);
690690
msgBox.addButton(QMessageBox::No);
691691
msgBox.setDefaultButton(QMessageBox::Yes);
692-
int dlgResult = msgBox.exec();
692+
const int dlgResult = msgBox.exec();
693693
if (dlgResult == QMessageBox::Yes) {
694694
QString path = checkDir.canonicalPath();
695695
if (!path.endsWith("/"))
@@ -712,7 +712,7 @@ void MainWindow::analyzeDirectory()
712712
msgBox.addButton(QMessageBox::Yes);
713713
msgBox.addButton(QMessageBox::No);
714714
msgBox.setDefaultButton(QMessageBox::Yes);
715-
int dlgResult = msgBox.exec();
715+
const int dlgResult = msgBox.exec();
716716
if (dlgResult == QMessageBox::Yes) {
717717
doAnalyzeFiles(dir);
718718
}
@@ -1199,7 +1199,7 @@ void MainWindow::openResults()
11991199
msgBox.addButton(QMessageBox::Yes);
12001200
msgBox.addButton(QMessageBox::No);
12011201
msgBox.setDefaultButton(QMessageBox::Yes);
1202-
int dlgResult = msgBox.exec();
1202+
const int dlgResult = msgBox.exec();
12031203
if (dlgResult == QMessageBox::No) {
12041204
return;
12051205
}
@@ -1257,7 +1257,7 @@ void MainWindow::enableCheckButtons(bool enable)
12571257

12581258
void MainWindow::enableResultsButtons()
12591259
{
1260-
bool enabled = mUI->mResults->hasResults();
1260+
const bool enabled = mUI->mResults->hasResults();
12611261
mUI->mActionClearResults->setEnabled(enabled);
12621262
mUI->mActionSave->setEnabled(enabled);
12631263
mUI->mActionPrint->setEnabled(enabled);
@@ -1321,7 +1321,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
13211321
this);
13221322

13231323
msg.setDefaultButton(QMessageBox::No);
1324-
int rv = msg.exec();
1324+
const int rv = msg.exec();
13251325
if (rv == QMessageBox::Yes) {
13261326
// This isn't really very clean way to close threads but since the app is
13271327
// exiting it doesn't matter.
@@ -1781,7 +1781,7 @@ void MainWindow::openRecentProject()
17811781
this);
17821782

17831783
msg.setDefaultButton(QMessageBox::No);
1784-
int rv = msg.exec();
1784+
const int rv = msg.exec();
17851785
if (rv == QMessageBox::Yes) {
17861786
removeProjectMRU(project);
17871787
}

gui/projectfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ void ProjectFile::readTagWarnings(QXmlStreamReader &reader, const QString &tag)
625625
case QXmlStreamReader::StartElement:
626626
// Read library-elements
627627
if (reader.name().toString() == CppcheckXml::WarningElementName) {
628-
std::size_t hash = reader.attributes().value(QString(), CppcheckXml::HashAttributeName).toULongLong();
628+
const std::size_t hash = reader.attributes().value(QString(), CppcheckXml::HashAttributeName).toULongLong();
629629
mWarningTags[hash] = tag;
630630
}
631631
break;

gui/projectfiledialog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
173173

174174
// Platforms..
175175
Platforms platforms;
176-
for (cppcheck::Platform::PlatformType builtinPlatform : builtinPlatforms)
176+
for (const cppcheck::Platform::PlatformType builtinPlatform : builtinPlatforms)
177177
mUI->mComboBoxPlatform->addItem(platforms.get(builtinPlatform).mTitle);
178178
QStringList platformFiles;
179179
for (QString sp : searchPaths) {
@@ -411,7 +411,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
411411
if (mUI->mComboBoxPlatform->currentText().endsWith(".xml"))
412412
projectFile->setPlatform(mUI->mComboBoxPlatform->currentText());
413413
else {
414-
int i = mUI->mComboBoxPlatform->currentIndex();
414+
const int i = mUI->mComboBoxPlatform->currentIndex();
415415
if (i < numberOfBuiltinPlatforms)
416416
projectFile->setPlatform(cppcheck::Platform::platformString(builtinPlatforms[i]));
417417
else
@@ -504,8 +504,8 @@ void ProjectFileDialog::browseBuildDir()
504504
void ProjectFileDialog::updatePathsAndDefines()
505505
{
506506
const QString &fileName = mUI->mEditImportProject->text();
507-
bool importProject = !fileName.isEmpty();
508-
bool hasConfigs = fileName.endsWith(".sln") || fileName.endsWith(".vcxproj");
507+
const bool importProject = !fileName.isEmpty();
508+
const bool hasConfigs = fileName.endsWith(".sln") || fileName.endsWith(".vcxproj");
509509
mUI->mBtnClearImportProject->setEnabled(importProject);
510510
mUI->mListCheckPaths->setEnabled(!importProject);
511511
mUI->mListIncludeDirs->setEnabled(!importProject);
@@ -730,7 +730,7 @@ void ProjectFileDialog::setLibraries(const QStringList &libraries)
730730
void ProjectFileDialog::addSingleSuppression(const Suppressions::Suppression &suppression)
731731
{
732732
QString suppression_name;
733-
static char sep = QDir::separator().toLatin1();
733+
static const char sep = QDir::separator().toLatin1();
734734
bool found_relative = false;
735735

736736
// Replace relative file path in the suppression with the absolute one
@@ -872,7 +872,7 @@ void ProjectFileDialog::removeSuppression()
872872
if (!item)
873873
return;
874874

875-
int suppressionIndex = getSuppressionIndex(item->text());
875+
const int suppressionIndex = getSuppressionIndex(item->text());
876876
if (suppressionIndex >= 0)
877877
mSuppressions.removeAt(suppressionIndex);
878878
delete item;
@@ -882,7 +882,7 @@ void ProjectFileDialog::editSuppression(const QModelIndex & /*index*/)
882882
{
883883
const int row = mUI->mListSuppressions->currentRow();
884884
QListWidgetItem *item = mUI->mListSuppressions->item(row);
885-
int suppressionIndex = getSuppressionIndex(item->text());
885+
const int suppressionIndex = getSuppressionIndex(item->text());
886886
if (suppressionIndex >= 0) { // TODO what if suppression is not found?
887887
NewSuppressionDialog dlg;
888888
dlg.setSuppression(mSuppressions[suppressionIndex]);

gui/resultstree.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void ResultsTree::showHiddenResults()
469469
{
470470
//Clear the "hide" flag for each item
471471
mHiddenMessageId.clear();
472-
int filecount = mModel.rowCount();
472+
const int filecount = mModel.rowCount();
473473
for (int i = 0; i < filecount; i++) {
474474
QStandardItem *fileItem = mModel.item(i, 0);
475475
if (!fileItem)
@@ -479,7 +479,7 @@ void ResultsTree::showHiddenResults()
479479
data[HIDE] = false;
480480
fileItem->setData(QVariant(data));
481481

482-
int errorcount = fileItem->rowCount();
482+
const int errorcount = fileItem->rowCount();
483483
for (int j = 0; j < errorcount; j++) {
484484
QStandardItem *child = fileItem->child(j, 0);
485485
if (child) {
@@ -498,7 +498,7 @@ void ResultsTree::refreshTree()
498498
{
499499
mVisibleErrors = false;
500500
//Get the amount of files in the tree
501-
int filecount = mModel.rowCount();
501+
const int filecount = mModel.rowCount();
502502

503503
for (int i = 0; i < filecount; i++) {
504504
//Get file i
@@ -508,7 +508,7 @@ void ResultsTree::refreshTree()
508508
}
509509

510510
//Get the amount of errors this file contains
511-
int errorcount = fileItem->rowCount();
511+
const int errorcount = fileItem->rowCount();
512512

513513
//By default it shouldn't be visible
514514
bool show = false;
@@ -820,7 +820,7 @@ void ResultsTree::startApplication(QStandardItem *target, int application)
820820
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
821821

822822
// this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6
823-
bool success = SUPPRESS_DEPRECATED_WARNING(QProcess::startDetached(cmdLine));
823+
const bool success = SUPPRESS_DEPRECATED_WARNING(QProcess::startDetached(cmdLine));
824824
if (!success) {
825825
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program);
826826

@@ -983,7 +983,7 @@ void ResultsTree::hideAllIdResult()
983983
mHiddenMessageId.append(messageId);
984984

985985
// hide all errors with that message Id
986-
int filecount = mModel.rowCount();
986+
const int filecount = mModel.rowCount();
987987
for (int i = 0; i < filecount; i++) {
988988
//Get file i
989989
QStandardItem *file = mModel.item(i, 0);
@@ -992,7 +992,7 @@ void ResultsTree::hideAllIdResult()
992992
}
993993

994994
//Get the amount of errors this file contains
995-
int errorcount = file->rowCount();
995+
const int errorcount = file->rowCount();
996996

997997
for (int j = 0; j < errorcount; j++) {
998998
//Get the error itself
@@ -1239,7 +1239,7 @@ void ResultsTree::updateFromOldReport(const QString &filename)
12391239
QStandardItem *error = fileItem->child(j,0);
12401240
ErrorItem errorItem;
12411241
readErrorItem(error, &errorItem);
1242-
int oldErrorIndex = indexOf(oldErrors, errorItem);
1242+
const int oldErrorIndex = indexOf(oldErrors, errorItem);
12431243
QVariantMap data = error->data().toMap();
12441244

12451245
// New error .. set the "sinceDate" property

0 commit comments

Comments
 (0)