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

fix: get rid of some more warnings #5672

Merged
merged 7 commits into from
Oct 27, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
- Dev: Refactored static `MessageBuilder` helpers to standalone functions. (#5652)
- Dev: Decoupled reply parsing from `MessageBuilder`. (#5660, #5668)
- Dev: Refactored IRC message building. (#5663)
- Dev: Fixed some compiler warnings. (#5672)

## 2.5.1

Expand Down
2 changes: 1 addition & 1 deletion mocks/include/mocks/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class Helix : public IHelix
// contains a comma
MOCK_METHOD(
void, getChatters,
(QString broadcasterID, QString moderatorID, int maxChattersToFetch,
(QString broadcasterID, QString moderatorID, size_t maxChattersToFetch,
ResultCallback<HelixChatters> successCallback,
(FailureCallback<HelixGetChattersError, QString> failureCallback)),
(override)); // getChatters
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(LIBRARY_PROJECT "${PROJECT_NAME}-lib")
set(VERSION_PROJECT "${LIBRARY_PROJECT}-version")
set(EXECUTABLE_PROJECT "${PROJECT_NAME}")
add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x050F00)
add_compile_definitions(QT_WARN_DEPRECATED_UP_TO=0x050F00)

# registers the native messageing host
option(CHATTERINO_DEBUG_NATIVE_MESSAGES "Debug native messages" OFF)
Expand Down
4 changes: 3 additions & 1 deletion src/common/ProviderId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace chatterino {

enum class ProviderId { Twitch, Irc };
enum class ProviderId { // NOLINT(performance-enum-size)
Twitch,
};
//
} // namespace chatterino
10 changes: 6 additions & 4 deletions src/common/SignalVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class SignalVector
}
else
{
assert(index >= 0 && index <= this->items_.size());
assert(index >= 0 &&
index <= static_cast<int>(this->items_.size()));
}

this->items_.insert(this->items_.begin() + index, item);
Expand Down Expand Up @@ -116,7 +117,7 @@ class SignalVector
void removeAt(int index, void *caller = nullptr)
{
assertInGuiThread();
assert(index >= 0 && index < int(this->items_.size()));
assert(index >= 0 && index < static_cast<int>(this->items_.size()));

T item = this->items_[index];
this->items_.erase(this->items_.begin() + index);
Expand All @@ -132,13 +133,14 @@ class SignalVector
{
assertInGuiThread();

for (int index = 0; index < this->items_.size(); ++index)
for (size_t index = 0; index < this->items_.size(); ++index)
{
T item = this->items_[index];
if (matcher(item))
{
this->items_.erase(this->items_.begin() + index);
SignalVectorItemEvent<T> args{item, index, caller};
SignalVectorItemEvent<T> args{item, static_cast<int>(index),
caller};
this->itemRemoved.invoke(args);
this->itemsChanged_();
return true;
Expand Down
38 changes: 22 additions & 16 deletions src/common/SignalVectorModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SignalVectorModel : public QAbstractTableModel,
}
// get row index
int index = this->getModelIndexFromVectorIndex(args.index);
assert(index >= 0 && index <= this->rows_.size());
assert(index >= 0 && index <= static_cast<int>(this->rows_.size()));

// get row items
std::vector<QStandardItem *> row = this->createRow();
Expand Down Expand Up @@ -75,7 +75,7 @@ class SignalVectorModel : public QAbstractTableModel,
}

int row = this->getModelIndexFromVectorIndex(args.index);
assert(row >= 0 && row <= this->rows_.size());
assert(row >= 0 && row <= static_cast<int>(this->rows_.size()));

// remove row
std::vector<QStandardItem *> items = this->rows_[row].items;
Expand Down Expand Up @@ -130,7 +130,8 @@ class SignalVectorModel : public QAbstractTableModel,
{
int row = index.row();
int column = index.column();
if (row < 0 || column < 0 || row >= this->rows_.size() ||
if (row < 0 || column < 0 ||
row >= static_cast<int>(this->rows_.size()) ||
column >= this->columnCount_)
{
return QVariant();
Expand All @@ -144,15 +145,16 @@ class SignalVectorModel : public QAbstractTableModel,
{
int row = index.row();
int column = index.column();
if (row < 0 || column < 0 || row >= this->rows_.size() ||
if (row < 0 || column < 0 ||
row >= static_cast<int>(this->rows_.size()) ||
column >= this->columnCount_)
{
return false;
}

Row &rowItem = this->rows_[row];

assert(this->columnCount_ == rowItem.items.size());
assert(this->columnCount_ == static_cast<int>(rowItem.items.size()));

auto &cell = rowItem.items[column];

Expand All @@ -167,7 +169,7 @@ class SignalVectorModel : public QAbstractTableModel,
int vecRow = this->getVectorIndexFromModelIndex(row);
// TODO: This is only a safety-thing for when we modify data that's being modified right now.
// It should not be necessary, but it would require some rethinking about this surrounding logic
if (vecRow >= this->vector_->readOnly()->size())
if (vecRow >= static_cast<int>(this->vector_->readOnly()->size()))
{
return false;
}
Expand Down Expand Up @@ -224,18 +226,19 @@ class SignalVectorModel : public QAbstractTableModel,
{
int row = index.row(), column = index.column();

if (row < 0 || column < 0 || row >= this->rows_.size() ||
if (row < 0 || column < 0 ||
row >= static_cast<int>(this->rows_.size()) ||
column >= this->columnCount_)
{
return Qt::NoItemFlags;
}

assert(row >= 0 && row < this->rows_.size() && column >= 0 &&
column < this->columnCount_);
assert(row >= 0 && row < static_cast<int>(this->rows_.size()) &&
column >= 0 && column < this->columnCount_);

const auto &rowItem = this->rows_[row];

assert(this->columnCount_ == rowItem.items.size());
assert(this->columnCount_ == static_cast<int>(rowItem.items.size()));

return rowItem.items[column]->flags();
}
Expand Down Expand Up @@ -267,7 +270,8 @@ class SignalVectorModel : public QAbstractTableModel,
return false;
}

assert(sourceRow >= 0 && sourceRow < this->rows_.size());
assert(sourceRow >= 0 &&
sourceRow < static_cast<int>(this->rows_.size()));

int signalVectorRow = this->getVectorIndexFromModelIndex(sourceRow);
this->beginMoveRows(sourceParent, sourceRow, sourceRow,
Expand All @@ -294,7 +298,7 @@ class SignalVectorModel : public QAbstractTableModel,
return false;
}

assert(row >= 0 && row < this->rows_.size());
assert(row >= 0 && row < static_cast<int>(this->rows_.size()));

int signalVectorRow = this->getVectorIndexFromModelIndex(row);
this->vector_->removeAt(signalVectorRow);
Expand Down Expand Up @@ -337,8 +341,10 @@ class SignalVectorModel : public QAbstractTableModel,
int from = data->data("chatterino_row_id").toInt();
int to = parent.row();

int vectorFrom = this->getVectorIndexFromModelIndex(from);
int vectorTo = this->getVectorIndexFromModelIndex(to);
auto vectorFrom =
static_cast<size_t>(this->getVectorIndexFromModelIndex(from));
auto vectorTo =
static_cast<size_t>(this->getVectorIndexFromModelIndex(to));

if (vectorFrom < 0 || vectorFrom > this->vector_->raw().size() ||
vectorTo < 0 || vectorTo > this->vector_->raw().size())
Expand Down Expand Up @@ -402,7 +408,7 @@ class SignalVectorModel : public QAbstractTableModel,

void insertCustomRow(std::vector<QStandardItem *> row, int index)
{
assert(index >= 0 && index <= this->rows_.size());
assert(index >= 0 && index <= static_cast<int>(this->rows_.size()));

this->beginInsertRows(QModelIndex(), index, index);
this->rows_.insert(this->rows_.begin() + index,
Expand All @@ -412,7 +418,7 @@ class SignalVectorModel : public QAbstractTableModel,

void removeCustomRow(int index)
{
assert(index >= 0 && index <= this->rows_.size());
assert(index >= 0 && index <= static_cast<int>(this->rows_.size()));
assert(this->rows_[index].isCustomRow);

this->beginRemoveRows(QModelIndex(), index, index);
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/completion/sources/UnifiedSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void UnifiedSource::addToListModel(GenericListModel &model,
source->addToListModel(model, maxCount - used);
// Calculate how many items have been added so far
used = model.rowCount() - startingSize;
if (used >= maxCount)
if (used >= static_cast<int>(maxCount))
{
// Used up all of limit
break;
Expand All @@ -58,15 +58,15 @@ void UnifiedSource::addToStringList(QStringList &list, size_t maxCount,
}

// Make sure to only add maxCount elements in total.
int startingSize = list.size();
int used = 0;
auto startingSize = list.size();
QStringList::size_type used = 0;

for (const auto &source : this->sources_)
{
source->addToStringList(list, maxCount - used, isFirstWord);
// Calculate how many items have been added so far
used = list.size() - startingSize;
if (used >= maxCount)
if (used >= static_cast<QStringList::size_type>(maxCount))
{
// Used up all of limit
break;
Expand Down
4 changes: 2 additions & 2 deletions src/messages/LimitedQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ class LimitedQueue
std::unique_lock lock(this->mutex_);

Equals eq;
for (int i = 0; i < this->buffer_.size(); ++i)
for (size_t i = 0; i < this->buffer_.size(); ++i)
{
if (eq(this->buffer_[i], needle))
{
this->buffer_[i] = replacement;
return i;
return static_cast<int>(i);
}
}
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ QString formatUpdatedEmoteList(const QString &platform,
text += QString(" %1 %2 emotes ").arg(emoteNames.size()).arg(platform);
}

auto i = 0;
size_t i = 0;
for (const auto &emoteName : emoteNames)
{
i++;
Expand Down
3 changes: 2 additions & 1 deletion src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void MessageLayoutContainer::breakLine()
this->lineStart_ = this->elements_.size();
// this->currentX = (int)(this->scale * 8);

if (this->canCollapse() && this->line_ + 1 >= maxUncollapsedLines())
if (this->canCollapse() &&
static_cast<int>(this->line_ + 1) >= maxUncollapsedLines())
{
this->canAddMessages_ = false;
return;
Expand Down
5 changes: 3 additions & 2 deletions src/messages/layouts/MessageLayoutElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,10 @@ int TextLayoutElement::getXFromIndex(size_t index)
else if (index < static_cast<size_t>(this->getText().size()))
{
int x = 0;
for (int i = 0; i < index; i++)
for (size_t i = 0; i < index; i++)
{
x += metrics.horizontalAdvance(this->getText()[i]);
x += metrics.horizontalAdvance(
this->getText()[static_cast<QString::size_type>(i)]);
}
return x + this->getRect().left();
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/twitch/IrcMessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ float IrcMessageHandler::similarity(
float similarityPercent = 0.0F;
int checked = 0;

for (int i = 1; i <= messages.size(); ++i)
for (size_t i = 1; i <= messages.size(); ++i)
{
if (checked >= getSettings()->hideSimilarMaxMessagesToCheck)
{
Expand Down
6 changes: 3 additions & 3 deletions src/providers/twitch/api/Helix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ void Helix::updateChatSettings(

void Helix::onFetchChattersSuccess(
std::shared_ptr<HelixChatters> finalChatters, QString broadcasterID,
QString moderatorID, int maxChattersToFetch,
QString moderatorID, size_t maxChattersToFetch,
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'moderatorID' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

src/providers/twitch/api/Helix.hpp:1507:

-         QString moderatorID, size_t maxChattersToFetch,
+         const QString& moderatorID, size_t maxChattersToFetch,
Suggested change
QString moderatorID, size_t maxChattersToFetch,
const QString& moderatorID, size_t maxChattersToFetch,

ResultCallback<HelixChatters> successCallback,
FailureCallback<HelixGetChattersError, QString> failureCallback,
HelixChatters chatters)
Expand Down Expand Up @@ -2022,7 +2022,7 @@ void Helix::fetchChatters(

void Helix::onFetchModeratorsSuccess(
std::shared_ptr<std::vector<HelixModerator>> finalModerators,
QString broadcasterID, int maxModeratorsToFetch,
QString broadcasterID, size_t maxModeratorsToFetch,
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'broadcasterID' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

src/providers/twitch/api/Helix.hpp:1522:

-         QString broadcasterID, size_t maxModeratorsToFetch,
+         const QString& broadcasterID, size_t maxModeratorsToFetch,
Suggested change
QString broadcasterID, size_t maxModeratorsToFetch,
const QString& broadcasterID, size_t maxModeratorsToFetch,

ResultCallback<std::vector<HelixModerator>> successCallback,
FailureCallback<HelixGetModeratorsError, QString> failureCallback,
HelixModerators moderators)
Expand Down Expand Up @@ -2459,7 +2459,7 @@ void Helix::sendWhisper(

// https://dev.twitch.tv/docs/api/reference#get-chatters
void Helix::getChatters(
QString broadcasterID, QString moderatorID, int maxChattersToFetch,
QString broadcasterID, QString moderatorID, size_t maxChattersToFetch,
ResultCallback<HelixChatters> successCallback,
FailureCallback<HelixGetChattersError, QString> failureCallback)
{
Expand Down
8 changes: 4 additions & 4 deletions src/providers/twitch/api/Helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ class IHelix
// This will follow the returned cursor and return up to `maxChattersToFetch` chatters
// https://dev.twitch.tv/docs/api/reference#get-chatters
virtual void getChatters(
QString broadcasterID, QString moderatorID, int maxChattersToFetch,
QString broadcasterID, QString moderatorID, size_t maxChattersToFetch,
ResultCallback<HelixChatters> successCallback,
FailureCallback<HelixGetChattersError, QString> failureCallback) = 0;

Expand Down Expand Up @@ -1417,7 +1417,7 @@ class Helix final : public IHelix
// This will follow the returned cursor and return up to `maxChattersToFetch` chatters
// https://dev.twitch.tv/docs/api/reference#get-chatters
void getChatters(
QString broadcasterID, QString moderatorID, int maxChattersToFetch,
QString broadcasterID, QString moderatorID, size_t maxChattersToFetch,
ResultCallback<HelixChatters> successCallback,
FailureCallback<HelixGetChattersError, QString> failureCallback) final;

Expand Down Expand Up @@ -1505,7 +1505,7 @@ class Helix final : public IHelix
// Recursive boy
void onFetchChattersSuccess(
std::shared_ptr<HelixChatters> finalChatters, QString broadcasterID,
QString moderatorID, int maxChattersToFetch,
QString moderatorID, size_t maxChattersToFetch,
ResultCallback<HelixChatters> successCallback,
FailureCallback<HelixGetChattersError, QString> failureCallback,
HelixChatters chatters);
Expand All @@ -1520,7 +1520,7 @@ class Helix final : public IHelix
// Recursive boy
void onFetchModeratorsSuccess(
std::shared_ptr<std::vector<HelixModerator>> finalModerators,
QString broadcasterID, int maxModeratorsToFetch,
QString broadcasterID, size_t maxModeratorsToFetch,
ResultCallback<std::vector<HelixModerator>> successCallback,
FailureCallback<HelixGetModeratorsError, QString> failureCallback,
HelixModerators moderators);
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/TooltipWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void TooltipWidget::set(const std::vector<TooltipEntry> &entries,

this->setVisibleEntries(entries.size());

for (int i = 0; i < entries.size(); ++i)
for (size_t i = 0; i < entries.size(); ++i)
{
if (auto *entryWidget = this->entryAt(i))
if (auto *entryWidget = this->entryAt(static_cast<int>(i)))
{
const auto &entry = entries[i];
entryWidget->setImage(entry.image);
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/dialogs/EditHotkeyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void EditHotkeyDialog::setFromHotkey(std::shared_ptr<Hotkey> hotkey)
this->ui_->easyArgsLabel->setText(def->argumentsPrompt);
this->ui_->easyArgsLabel->setToolTip(def->argumentsPromptHover);
int matchIdx = -1;
for (int i = 0; i < def->possibleArguments.size(); i++)
for (size_t i = 0; i < def->possibleArguments.size(); i++)
{
const auto &[displayText, argData] = def->possibleArguments.at(i);
this->ui_->easyArgsPicker->addItem(displayText);
Expand All @@ -90,7 +90,7 @@ void EditHotkeyDialog::setFromHotkey(std::shared_ptr<Hotkey> hotkey)
continue;
}
bool matches = true;
for (int j = 0; j < argData.size(); j++)
for (size_t j = 0; j < argData.size(); j++)
{
if (argData.at(j) != hotkey->arguments().at(j))
{
Expand All @@ -100,7 +100,7 @@ void EditHotkeyDialog::setFromHotkey(std::shared_ptr<Hotkey> hotkey)
}
if (matches)
{
matchIdx = i;
matchIdx = static_cast<int>(i);
}
}
if (matchIdx != -1)
Expand Down
Loading
Loading