chore: fix more warnings.

Temporarily enabled `-Wall` and fixed more warnings, but there are several uninitialized variables usages which may require review by the code author in order to ensure the refactor is correct so we leave these additional warnings disabled for now.

Fixed:
* removed unused lambda captures
* removed unused variables
* fixed sign comparisons between variables
This commit is contained in:
Michael Werle 2023-08-29 14:16:28 +09:00
parent 39539746e5
commit fd6efb474d
28 changed files with 59 additions and 63 deletions

View File

@ -1,6 +1,13 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_compile_options(-Werror=switch)
# Uncomment to compile with more warnings
#add_compile_options(-Wall)
# Uncomment to compile with even more warnings
#add_compile_options(-Wextra)
# TODO: currently there are too many unused parameters which overwhelms the
# warning output with `-Wall`. So let's leave fixing these for later.
add_compile_options(-Wno-unused-parameter)
add_subdirectory(util)
add_subdirectory(cli)

View File

@ -85,7 +85,7 @@ QVBoxLayout *ExternalToolsDialog::createUserDefinedLayout(const QString &type) {
table->resizeColumnsToContents();
});
connect(footer, &Footer::minusClicked, [this, table, model] {
connect(footer, &Footer::minusClicked, [table, model] {
QModelIndexList indexes = table->selectionModel()->selectedRows(0);
foreach (const QModelIndex &index, indexes)
model->remove(index.data(Qt::DisplayRole).toString());

View File

@ -698,7 +698,7 @@ void StartDialog::updateButtons() {
open->setEnabled(false);
} else {
Account *account = parent.data(AccountRole).value<Account *>();
if (Repository *repo = index.data(RepositoryRole).value<Repository *>()) {
if (nullptr != index.data(RepositoryRole).value<Repository *>()) {
if (account->repositoryPath(index.row()).isEmpty())
clone = true;
} else {

View File

@ -128,7 +128,7 @@ void SurfaceImpl::Polygon(Point *pts, size_t npts, ColourDesired fore,
PenColour(fore);
QVarLengthArray<QPoint, 8> qpts(npts);
for (int i = 0; i < npts; i++)
for (size_t i = 0; i < npts; i++)
qpts[i] = QPoint(pts[i].x, pts[i].y);
QPainter *painter = GetPainter();
@ -306,7 +306,7 @@ void SurfaceImpl::MeasureWidths(Font &font, std::string_view s,
QTextLine tl = tlay.createLine();
tlay.endLayout();
int i = 0;
size_t i = 0;
int ui = 0;
int fit = su.size();
const unsigned char *us = reinterpret_cast<const unsigned char *>(s.data());
@ -468,9 +468,6 @@ void Window::SetCursor(Cursor curs) {
case cursorText:
shape = Qt::IBeamCursor;
break;
case cursorArrow:
shape = Qt::ArrowCursor;
break;
case cursorUp:
shape = Qt::UpArrowCursor;
break;
@ -486,8 +483,7 @@ void Window::SetCursor(Cursor curs) {
case cursorHand:
shape = Qt::PointingHandCursor;
break;
case cursorInvalid: // fall through
case cursorReverseArrow:
default:
shape = Qt::ArrowCursor;
break;
}

View File

@ -520,7 +520,6 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) {
const unsigned int ucWidth = commitStr.at(i).isHighSurrogate() ? 2 : 1;
const QString oneCharUTF16 = commitStr.mid(i, ucWidth);
const QByteArray oneChar = oneCharUTF16.toUtf8();
const int oneCharLen = oneChar.length();
InsertCharacter(oneChar.toStdString(), CharacterSource::directInput);
i += ucWidth;

View File

@ -43,8 +43,6 @@ QPixmap stagedUnstagedIcon(const bool &checked, const QColor &background,
QRect(QPoint(0, 0), QSize(fontHeight - 2, fontHeight - 2)));
}
const float textHeightFactorCheckBoxSize = 2.0;
} // namespace
extern LexerModule lmLPeg;

View File

@ -195,7 +195,7 @@ QByteArray Patch::header(int hidx) const {
const git_diff_hunk *hunk = nullptr;
int result = git_patch_get_hunk(&hunk, nullptr, d.data(), hidx);
return !result ? hunk->header : QByteArray();
return (GIT_OK == result) ? hunk->header : QByteArray();
}
const git_diff_hunk *Patch::header_struct(int hidx) const {
@ -204,7 +204,7 @@ const git_diff_hunk *Patch::header_struct(int hidx) const {
const git_diff_hunk *hunk = nullptr;
int result = git_patch_get_hunk(&hunk, nullptr, d.data(), hidx);
return hunk;
return (GIT_OK == result) ? hunk : nullptr;
}
int Patch::lineCount(int hidx) const {
@ -235,7 +235,7 @@ char Patch::lineOrigin(int hidx, int ln) const {
const git_diff_line *line = nullptr;
int result = git_patch_get_line_in_hunk(&line, d.data(), hidx, ln);
return !result ? line->origin : GIT_DIFF_LINE_CONTEXT;
return (GIT_OK == result) ? line->origin : GIT_DIFF_LINE_CONTEXT;
}
int Patch::lineNumber(int hidx, int ln, Diff::File file) const {
@ -256,7 +256,7 @@ git_off_t Patch::contentOffset(int hidx) const {
const git_diff_line *line = nullptr;
int result = git_patch_get_line_in_hunk(&line, d.data(), hidx,
0); // TODO: line index 0?
return result == 0 ? line->content_offset : 0;
return (GIT_OK == result) ? line->content_offset : 0;
}
QByteArray Patch::lineContent(int hidx, int ln) const {
@ -265,7 +265,7 @@ QByteArray Patch::lineContent(int hidx, int ln) const {
const git_diff_line *line = nullptr;
int result = git_patch_get_line_in_hunk(&line, d.data(), hidx, ln);
return !result ? QByteArray(line->content, line->content_len) : QByteArray();
return (GIT_OK == result) ? QByteArray(line->content, line->content_len) : QByteArray();
}
Patch::ConflictResolution Patch::conflictResolution(int hidx) {

View File

@ -36,8 +36,8 @@ const git_rebase_operation *Rebase::operation(size_t index) {
}
bool Rebase::hasNext() const {
int index = currentIndex();
int count = git_rebase_operation_entrycount(d.data());
size_t index = currentIndex();
size_t count = git_rebase_operation_entrycount(d.data());
return (count > 0 && (index == GIT_REBASE_NO_OPERATION || index < count - 1));
}

View File

@ -488,7 +488,7 @@ QStringList Repository::existingTags() const {
QStringList list;
for (int i = 0; i < array.count; i++) {
for (size_t i = 0; i < array.count; i++) {
list.append(array.strings[i]);
}
@ -746,7 +746,7 @@ QList<Remote> Repository::remotes() const {
return QList<Remote>();
QList<Remote> remotes;
for (int i = 0; i < names.count; ++i) {
for (size_t i = 0; i < names.count; ++i) {
if (Remote remote = lookupRemote(names.strings[i]))
remotes.append(remote);
}
@ -934,7 +934,6 @@ void Repository::rebaseContinue(const QString &commitMessage) {
}
}
// Loop over rebase operations.
int count = r.count();
while (r.hasNext()) {
git::Commit before = r.next();
if (!before.isValid()) {

View File

@ -30,8 +30,10 @@ const QString kThemeIconFmt = ":/%1_%2.png";
} // namespace
Account::Account(const QString &username)
: mMgr(new QNetworkAccessManager()), mUsername(username),
mError(new AccountError(this)), mProgress(new AccountProgress(this)) {
: mUsername(username),
mError(new AccountError(this)),
mProgress(new AccountProgress(this)),
mMgr(new QNetworkAccessManager()) {
QObject::connect(
mMgr, &QNetworkAccessManager::sslErrors,
[this](QNetworkReply *reply, const QList<QSslError> &errors) {

View File

@ -182,7 +182,7 @@ bool Index::write(PostingMap map) {
quint32 postCount = readVInt(postIn);
bool end = (newIt == newEnd || newIt.key() != it->key);
postings.reserve(postCount + (!end ? newIt.value().size() : 0));
for (int i = 0; i < postCount; ++i) {
for (quint32 i = 0; i < postCount; ++i) {
quint32 proxPos;
Posting posting;
posting.id = readVInt(postIn);
@ -243,7 +243,7 @@ QList<git::Commit> Index::commits(const QString &filter) const {
// Sort by commit date.
QList<git::Commit> commits = query->commits(this);
std::sort(commits.begin(), commits.end(),
[this](const git::Commit &lhs, const git::Commit &rhs) {
[](const git::Commit &lhs, const git::Commit &rhs) {
return (lhs.committer().date() > rhs.committer().date());
});
@ -288,7 +288,7 @@ QList<Index::Posting> Index::postings(const Term &term, bool positional) const {
// Read list.
QList<Posting> postings;
quint32 postCount = readVInt(in);
for (int i = 0; i < postCount; ++i) {
for (quint32 i = 0; i < postCount; ++i) {
quint32 proxPos;
Posting posting;
posting.id = readVInt(in);
@ -331,7 +331,7 @@ QList<Index::Posting> Index::postings(const Predicate &pred,
// Read list.
quint32 postCount = readVInt(in);
for (int i = 0; i < postCount; ++i) {
for (quint32 i = 0; i < postCount; ++i) {
quint32 proxPos;
Posting posting;
posting.id = readVInt(in);
@ -373,7 +373,7 @@ QMap<Index::Field, QStringList> Index::fieldMap(const QString &prefix) const {
// Read list.
QString name = it->key;
quint32 postCount = readVInt(in);
for (int i = 0; i < postCount; ++i) {
for (quint32 i = 0; i < postCount; ++i) {
quint8 field;
quint32 proxPos;
readVInt(in); // Discard id.
@ -508,7 +508,7 @@ void Index::readPositions(QDataStream &in, QVector<quint32> &positions) {
quint32 prev = 0;
quint32 count = readVInt(in);
positions.reserve(count);
for (int i = 0; i < count; ++i) {
for (quint32 i = 0; i < count; ++i) {
// Convert to absolute from delta.
quint32 position = prev + readVInt(in);
positions.append(position);

View File

@ -353,7 +353,7 @@ private:
QFile *mOut;
int mContextLines = 3;
int mTermLimit = 1000000;
quint32 mTermLimit = 1000000;
};
class Reduce {

View File

@ -1239,6 +1239,7 @@ git::Diff CommitList::selectedDiff() const {
DebugRefresh("Selected indices count: " << indexes.count());
for (const auto &index : indexes) {
const auto &id = index.data(CommitRole).value<git::Commit>().shortId();
(void)id; // Unused in release builds
DebugRefresh("Commit: " << id);
}
if (indexes.isEmpty())

View File

@ -430,10 +430,7 @@ void Node::addChild(const QStringList &pathPart, int patchIndex,
git::Index::StagedState
Node::stageState(const git::Index &idx, ParentStageState searchingState) const {
if (!hasChildren())
return idx.isStaged(path(true));
git::Index::StagedState childState;
git::Index::StagedState childState = idx.isStaged(path(true));
for (auto child : mChildren) {
childState = child->stageState(idx, searchingState);

View File

@ -85,7 +85,7 @@ _FileWidget::Header::Header(const git::Diff &diff, const git::Patch &patch,
git::RepositoryNotifier *notifier = patch.repo().notifier();
connect(notifier, &git::RepositoryNotifier::lfsLocksChanged, this,
[this, patch, lfsLockButton] {
[patch, lfsLockButton] {
bool locked = patch.repo().lfsIsLocked(patch.name());
lfsLockButton->setText(locked ? FileWidget::tr("Unlock")
: FileWidget::tr("Lock"));
@ -560,10 +560,7 @@ void FileWidget::updatePatch(const git::Patch &patch, const git::Patch &staged,
int hunkCount = patch.count();
for (int hidx = 0; hidx < hunkCount; ++hidx) {
HunkWidget *hunk = addHunk(mDiff, patch, staged, hidx, lfs, submodule);
int startLine = patch.lineNumber(hidx, 0, git::Diff::OldFile);
// hunk->header()->check()->setChecked(stagedHunks.contains(startLine));
// // not correct, because it could also only a part of the hunk staged
// (single lines)
patch.lineNumber(hidx, 0, git::Diff::OldFile);
mHunkLayout->addWidget(hunk);
}
} else {
@ -786,7 +783,7 @@ void FileWidget::discard() {
: FileWidget::tr("Discard Changes");
QPushButton *discard = dialog->addButton(button, QMessageBox::AcceptRole);
connect(discard, &QPushButton::clicked,
[this, untracked] { emit discarded(mModelIndex); });
[this] { emit discarded(mModelIndex); });
dialog->exec();
}

View File

@ -497,8 +497,6 @@ void HunkWidget::unstageSelected(int startLine, int end, bool emitSignal) {
void HunkWidget::discardDialog(int startLine, int end) {
QString name = mPatch.name();
int line = mPatch.lineNumber(mIndex, 0, git::Diff::NewFile);
QString title = HunkWidget::tr("Discard selected lines?");
QString text =
mPatch.isUntracked()

View File

@ -364,7 +364,7 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) {
mRedo = edit->addAction(tr("Redo"));
redoHotkey.use(mRedo);
connect(mRedo, &QAction::triggered, [this] {
connect(mRedo, &QAction::triggered, [] {
QWidget *widget = QApplication::focusWidget();
if (TextEditor *editor = qobject_cast<TextEditor *>(widget)) {
editor->redo();
@ -984,6 +984,7 @@ void MenuBar::updateCutCopyPaste() {
mPaste->setEnabled(canPaste);
mFindSelection->setEnabled(editor->hasSelectedText());
} else if (LogView *logView = qobject_cast<LogView *>(widget)) {
(void)logView; // unused
mCopy->setEnabled(true);
}
}

View File

@ -321,7 +321,7 @@ void ReferenceView::contextMenuEvent(QContextMenuEvent *event) {
git::Remote remote = ref.repo().defaultRemote();
if (remote.isValid()) {
menu.addAction(tr("Push Tag to %1").arg(remote.name()),
[this, ref, view, remote] { view->push(remote, ref); });
[ref, view, remote] { view->push(remote, ref); });
}
}

View File

@ -1458,7 +1458,7 @@ void RepoView::rebaseAboutToRebase(const git::Rebase rebase,
QString beforeText = before.link();
QString step = tr("%1/%2").arg(currIndex).arg(rebase.count());
QString text = tr("%1 - %2").arg(step, beforeText);
LogEntry *entry = mRebase->addEntry(text, tr("Apply"));
mRebase->addEntry(text, tr("Apply"));
}
void RepoView::rebaseConflict(const git::Rebase rebase) {
@ -2788,14 +2788,15 @@ void RepoView::refresh() { refresh(true); }
void RepoView::refresh(bool restoreSelection) {
// Fake head update.
uint32_t counter = 0;
auto dtw = findChild<DoubleTreeWidget *>();
if (dtw)
counter = dtw->setDiffCounter();
if (mRepo.head().isValid())
if (dtw) {
dtw->setDiffCounter();
}
if (mRepo.head().isValid()) {
DebugRefresh("Head name: " << mRepo.head().name());
else
} else {
DebugRefresh("Head invalid");
}
DebugRefresh("time: " << QDateTime::currentDateTime()
<< " Set diff counter: " << counter);
emit mRepo.notifier()->referenceUpdated(mRepo.head(), restoreSelection);

View File

@ -41,7 +41,7 @@ class PathspecWidget;
class ReferenceWidget;
class RemoteCallbacks;
class ToolBar;
class ContributorInfo;
struct ContributorInfo;
namespace git {
class Result;

View File

@ -709,7 +709,7 @@ SideBar::SideBar(TabWidget *tabs, QWidget *parent) : QWidget(parent) {
QAction *clone = plusMenu->addAction(tr("Clone Repository"));
connect(clone, &QAction::triggered, [this] {
CloneDialog *dialog = new CloneDialog(CloneDialog::Clone, this);
connect(dialog, &CloneDialog::accepted, [this, dialog] {
connect(dialog, &CloneDialog::accepted, [dialog] {
if (MainWindow *window = MainWindow::open(dialog->path()))
window->currentView()->addLogEntry(dialog->message(),
dialog->messageTitle());
@ -733,7 +733,7 @@ SideBar::SideBar(TabWidget *tabs, QWidget *parent) : QWidget(parent) {
QAction *init = plusMenu->addAction(tr("Initialize New Repository"));
connect(init, &QAction::triggered, [this] {
CloneDialog *dialog = new CloneDialog(CloneDialog::Init, this);
connect(dialog, &CloneDialog::accepted, [this, dialog] {
connect(dialog, &CloneDialog::accepted, [dialog] {
if (MainWindow *window = MainWindow::open(dialog->path()))
window->currentView()->addLogEntry(dialog->message(),
dialog->messageTitle());
@ -811,7 +811,7 @@ SideBar::SideBar(TabWidget *tabs, QWidget *parent) : QWidget(parent) {
QAction *clear = contextMenu->addAction(tr("Clear All Recent"));
connect(clear, &QAction::triggered,
[this] { RecentRepositories::instance()->clear(); });
[] { RecentRepositories::instance()->clear(); });
QAction *showFullPath = contextMenu->addAction(tr("Show Full Path"));
bool recentChecked = settings.value("start/recent/fullpath").toBool();

View File

@ -42,7 +42,7 @@ public:
addButton(QIcon(":/clone.png"), tr("Clone repository"));
connect(clone, &QPushButton::clicked, [this] {
CloneDialog *dialog = new CloneDialog(CloneDialog::Clone, this);
connect(dialog, &CloneDialog::accepted, [this, dialog] {
connect(dialog, &CloneDialog::accepted, [dialog] {
if (MainWindow *window = MainWindow::open(dialog->path()))
window->currentView()->addLogEntry(dialog->message(),
dialog->messageTitle());
@ -68,7 +68,7 @@ public:
addButton(QIcon(":/new.png"), tr("Initialize new repository"));
connect(init, &QPushButton::clicked, [this] {
CloneDialog *dialog = new CloneDialog(CloneDialog::Init, this);
connect(dialog, &CloneDialog::accepted, [this, dialog] {
connect(dialog, &CloneDialog::accepted, [dialog] {
if (MainWindow *window = MainWindow::open(dialog->path()))
window->currentView()->addLogEntry(dialog->message(),
dialog->messageTitle());

View File

@ -296,7 +296,7 @@ void TemplateDialog::exportTemplates(QString filename) {
}
QString templatesStr;
for (const auto tmpl : mNew) {
for (const auto &tmpl : mNew) {
QString name = tmpl.name;
QString value = tmpl.value;
value = value.replace(QStringLiteral("\n"), QStringLiteral("\\n"));

View File

@ -696,7 +696,6 @@ public:
initStyleOption(&opt);
QColor color = opt.palette.buttonText().color();
QColor light = (isEnabled() && isActiveWindow()) ? color.lighter() : color;
QPainter painter(this);
painter.setPen(QPen(color, 1.0));
@ -884,7 +883,7 @@ ToolBar::ToolBar(MainWindow *parent) : QToolBar(parent) {
QAction *appConfigAction = configMenu->addAction(tr("Application settings"));
connect(appConfigAction, &QAction::triggered,
[this] { SettingsDialog::openSharedInstance(); });
[] { SettingsDialog::openSharedInstance(); });
addWidget(new Spacer(4, this));

View File

@ -24,7 +24,7 @@ const QString kLinkFmt = "<a href='%1'>%2</a>";
} // namespace
TreeProxy::TreeProxy(bool staged, QObject *parent)
: mStaged(staged), QSortFilterProxyModel(parent) {}
: QSortFilterProxyModel(parent), mStaged(staged) {}
TreeProxy::~TreeProxy() {}

View File

@ -31,6 +31,7 @@ public:
void enableFilter(bool enable) { mFilter = enable; }
private:
using QSortFilterProxyModel::setData;
bool filterAcceptsRow(int source_row,
const QModelIndex &source_parent) const override;
bool mStaged{

View File

@ -65,7 +65,7 @@ Updater::Download::~Download() { delete mFile; }
Updater::Updater(QObject *parent) : QObject(parent) {
// Set up connections.
connect(&mMgr, &QNetworkAccessManager::sslErrors, this, &Updater::sslErrors);
connect(this, &Updater::upToDate, [this] {
connect(this, &Updater::upToDate, [] {
UpToDateDialog dialog;
dialog.exec();
});

View File

@ -90,7 +90,7 @@ public:
ignored = false;
// Start watching new directories.
int mask = (IN_CREATE | IN_ISDIR);
uint32_t mask = (IN_CREATE | IN_ISDIR);
if ((event->mask & mask) == mask)
watch(path);
}