fix: more MSVC warnings (#5137)

This commit is contained in:
nerix 2024-01-30 17:28:36 +01:00 committed by GitHub
parent a5e853573f
commit 954e19817c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 59 additions and 47 deletions

View file

@ -123,7 +123,7 @@
- Dev: Load less message history upon reconnects. (#5001, #5018) - Dev: Load less message history upon reconnects. (#5001, #5018)
- Dev: Removed the `NullablePtr` class. (#5091) - Dev: Removed the `NullablePtr` class. (#5091)
- Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014, #5108) - Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014, #5108)
- Dev: Fixed most compiler warnings. (#5028) - Dev: Fixed most compiler warnings. (#5028, #5137)
- Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747) - Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747)
- Dev: Refactor Args to be less of a singleton. (#5041) - Dev: Refactor Args to be less of a singleton. (#5041)
- Dev: Channels without any animated elements on screen will skip updates from the GIF timer. (#5042, #5043, #5045) - Dev: Channels without any animated elements on screen will skip updates from the GIF timer. (#5042, #5043, #5045)

View file

@ -935,6 +935,7 @@ target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
AB_CUSTOM_SETTINGS AB_CUSTOM_SETTINGS
IRC_STATIC IRC_STATIC
IRC_NAMESPACE=Communi IRC_NAMESPACE=Communi
$<$<BOOL:${WIN32}>:_WIN32_WINNT=0x0A00> # Windows 10
) )
if (USE_SYSTEM_QTKEYCHAIN) if (USE_SYSTEM_QTKEYCHAIN)
@ -1048,10 +1049,6 @@ if (MSVC)
# Someone adds /W3 before we add /W4. # Someone adds /W3 before we add /W4.
# This makes sure, only /W4 is specified. # This makes sure, only /W4 is specified.
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# 4505 - "unreferenced local version has been removed"
# Although this might give hints on dead code,
# there are some cases where it's distracting.
#
# 4100 - "unreferenced formal parameter" # 4100 - "unreferenced formal parameter"
# There are a lot of functions and methods where # There are a lot of functions and methods where
# an argument was given a name but never used. # an argument was given a name but never used.
@ -1062,6 +1059,11 @@ if (MSVC)
# These are implicit conversions from size_t to int/qsizetype. # These are implicit conversions from size_t to int/qsizetype.
# We don't use size_t in a lot of cases, since # We don't use size_t in a lot of cases, since
# Qt doesn't use it - it uses int (or qsizetype in Qt6). # Qt doesn't use it - it uses int (or qsizetype in Qt6).
#
# 4458 - "declaration of 'identifier' hides class member"
# We have a rule of exclusively using `this->`
# to access class members, thus it's fine to reclare a variable
# with the same name as a class member.
target_compile_options(${LIBRARY_PROJECT} PUBLIC target_compile_options(${LIBRARY_PROJECT} PUBLIC
/W4 /W4
# 5038 - warnings about initialization order # 5038 - warnings about initialization order
@ -1069,9 +1071,9 @@ if (MSVC)
# 4855 - implicit capture of 'this' via '[=]' is deprecated # 4855 - implicit capture of 'this' via '[=]' is deprecated
/w14855 /w14855
# Disable the following warnings (see reasoning above) # Disable the following warnings (see reasoning above)
/wd4505
/wd4100 /wd4100
/wd4267 /wd4267
/wd4458
# Enable updated '__cplusplus' macro - workaround for CMake#18837 # Enable updated '__cplusplus' macro - workaround for CMake#18837
/Zc:__cplusplus /Zc:__cplusplus
) )

View file

@ -82,7 +82,6 @@ LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
void Channel::addMessage(MessagePtr message, void Channel::addMessage(MessagePtr message,
std::optional<MessageFlags> overridingFlags) std::optional<MessageFlags> overridingFlags)
{ {
auto *app = getApp();
MessagePtr deleted; MessagePtr deleted;
if (!overridingFlags || !overridingFlags->has(MessageFlag::DoNotLog)) if (!overridingFlags || !overridingFlags->has(MessageFlag::DoNotLog))

View file

@ -1,6 +1,7 @@
#include "common/Credentials.hpp" #include "common/Credentials.hpp"
#include "Application.hpp" #include "Application.hpp"
#include "common/Modes.hpp"
#include "debug/AssertInGuiThread.hpp" #include "debug/AssertInGuiThread.hpp"
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
@ -41,7 +42,7 @@ bool useKeyring()
#ifdef NO_QTKEYCHAIN #ifdef NO_QTKEYCHAIN
return false; return false;
#endif #endif
if (getIApp()->getPaths().isPortable()) if (Modes::instance().isPortable)
{ {
return false; return false;
} }

View file

@ -7,12 +7,12 @@
namespace chatterino { namespace chatterino {
static bool isGuiThread() inline bool isGuiThread()
{ {
return QCoreApplication::instance()->thread() == QThread::currentThread(); return QCoreApplication::instance()->thread() == QThread::currentThread();
} }
static void assertInGuiThread() inline void assertInGuiThread()
{ {
#ifdef _DEBUG #ifdef _DEBUG
assert(isGuiThread()); assert(isGuiThread());

View file

@ -504,7 +504,7 @@ int TextLayoutElement::getXFromIndex(size_t index)
{ {
return this->getRect().left(); return this->getRect().left();
} }
else if (index < this->getText().size()) else if (index < static_cast<size_t>(this->getText().size()))
{ {
int x = 0; int x = 0;
for (int i = 0; i < index; i++) for (int i = 0; i < index; i++)

View file

@ -8,4 +8,16 @@ Message::Message(QJsonObject _json)
{ {
} }
std::optional<Message> parseBaseMessage(const QString &blob)
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull())
{
return std::nullopt;
}
return Message(jsonDoc.object());
}
} // namespace chatterino::seventv::eventapi } // namespace chatterino::seventv::eventapi

View file

@ -28,16 +28,6 @@ std::optional<InnerClass> Message::toInner()
return InnerClass{this->data}; return InnerClass{this->data};
} }
static std::optional<Message> parseBaseMessage(const QString &blob) std::optional<Message> parseBaseMessage(const QString &blob);
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull())
{
return std::nullopt;
}
return Message(jsonDoc.object());
}
} // namespace chatterino::seventv::eventapi } // namespace chatterino::seventv::eventapi

View file

@ -2703,8 +2703,12 @@ void Helix::updateShieldMode(
Qt::CaseInsensitive)) Qt::CaseInsensitive))
{ {
failureCallback(Error::UserMissingScope, message); failureCallback(Error::UserMissingScope, message);
break;
} }
failureCallback(Error::Forwarded, message);
} }
break;
case 401: { case 401: {
failureCallback(Error::Forwarded, message); failureCallback(Error::Forwarded, message);
} }

View file

@ -16,4 +16,16 @@ PubSubMessage::PubSubMessage(QJsonObject _object)
} }
} }
std::optional<PubSubMessage> parsePubSubBaseMessage(const QString &blob)
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull())
{
return std::nullopt;
}
return PubSubMessage(jsonDoc.object());
}
} // namespace chatterino } // namespace chatterino

View file

@ -45,17 +45,7 @@ std::optional<InnerClass> PubSubMessage::toInner()
return InnerClass{this->nonce, data}; return InnerClass{this->nonce, data};
} }
static std::optional<PubSubMessage> parsePubSubBaseMessage(const QString &blob) std::optional<PubSubMessage> parsePubSubBaseMessage(const QString &blob);
{
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull())
{
return std::nullopt;
}
return PubSubMessage(jsonDoc.object());
}
} // namespace chatterino } // namespace chatterino

View file

@ -2,6 +2,7 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/Literals.hpp" #include "common/Literals.hpp"
#include "common/Modes.hpp"
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include "debug/AssertInGuiThread.hpp" #include "debug/AssertInGuiThread.hpp"
#include "providers/twitch/TwitchIrcServer.hpp" #include "providers/twitch/TwitchIrcServer.hpp"
@ -40,7 +41,7 @@ void registerNmManifest(const Paths &paths, const QString &manifestFilename,
void registerNmHost(const Paths &paths) void registerNmHost(const Paths &paths)
{ {
if (paths.isPortable()) if (Modes::instance().isPortable)
{ {
return; return;
} }

View file

@ -86,7 +86,7 @@ void Paths::initRootDirectory()
this->rootAppDataDirectory = [&]() -> QString { this->rootAppDataDirectory = [&]() -> QString {
// portable // portable
if (this->isPortable()) if (Modes::instance().isPortable)
{ {
return QCoreApplication::applicationDirPath(); return QCoreApplication::applicationDirPath();
} }

View file

@ -90,7 +90,7 @@ void Updates::installUpdates()
box->exec(); box->exec();
QDesktopServices::openUrl(this->updateGuideLink_); QDesktopServices::openUrl(this->updateGuideLink_);
#elif defined Q_OS_WIN #elif defined Q_OS_WIN
if (this->paths.isPortable()) if (Modes::instance().isPortable)
{ {
QMessageBox *box = QMessageBox *box =
new QMessageBox(QMessageBox::Information, "Chatterino Update", new QMessageBox(QMessageBox::Information, "Chatterino Update",

View file

@ -5,7 +5,7 @@
namespace chatterino { namespace chatterino {
static auto defaultItemFlags(bool selectable) inline auto defaultItemFlags(bool selectable)
{ {
return Qt::ItemIsEnabled | return Qt::ItemIsEnabled |
(selectable ? Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | (selectable ? Qt::ItemIsSelectable | Qt::ItemIsDragEnabled |
@ -13,7 +13,7 @@ static auto defaultItemFlags(bool selectable)
: Qt::ItemFlag()); : Qt::ItemFlag());
} }
static void setBoolItem(QStandardItem *item, bool value, inline void setBoolItem(QStandardItem *item, bool value,
bool userCheckable = true, bool selectable = true) bool userCheckable = true, bool selectable = true)
{ {
item->setFlags( item->setFlags(
@ -22,7 +22,7 @@ static void setBoolItem(QStandardItem *item, bool value,
item->setCheckState(value ? Qt::Checked : Qt::Unchecked); item->setCheckState(value ? Qt::Checked : Qt::Unchecked);
} }
static void setStringItem(QStandardItem *item, const QString &value, inline void setStringItem(QStandardItem *item, const QString &value,
bool editable = true, bool selectable = true) bool editable = true, bool selectable = true)
{ {
item->setData(value, Qt::EditRole); item->setData(value, Qt::EditRole);
@ -30,7 +30,7 @@ static void setStringItem(QStandardItem *item, const QString &value,
(editable ? (Qt::ItemIsEditable) : 0))); (editable ? (Qt::ItemIsEditable) : 0)));
} }
static void setFilePathItem(QStandardItem *item, const QUrl &value, inline void setFilePathItem(QStandardItem *item, const QUrl &value,
bool selectable = true) bool selectable = true)
{ {
item->setData(value, Qt::UserRole); item->setData(value, Qt::UserRole);
@ -40,7 +40,7 @@ static void setFilePathItem(QStandardItem *item, const QUrl &value,
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
} }
static void setColorItem(QStandardItem *item, const QColor &value, inline void setColorItem(QStandardItem *item, const QColor &value,
bool selectable = true) bool selectable = true)
{ {
item->setData(value, Qt::DecorationRole); item->setData(value, Qt::DecorationRole);
@ -49,7 +49,7 @@ static void setColorItem(QStandardItem *item, const QColor &value,
(selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags))); (selectable ? Qt::ItemIsSelectable : Qt::NoItemFlags)));
} }
static QStandardItem *emptyItem() inline QStandardItem *emptyItem()
{ {
auto *item = new QStandardItem(); auto *item = new QStandardItem();
item->setFlags(Qt::ItemFlags()); item->setFlags(Qt::ItemFlags());

View file

@ -220,9 +220,9 @@ public:
{ {
auto *combo = this->addDropdown(text, {}, std::move(toolTipText)); auto *combo = this->addDropdown(text, {}, std::move(toolTipText));
for (const auto &[text, userData] : items) for (const auto &[itemText, userData] : items)
{ {
combo->addItem(text, userData); combo->addItem(itemText, userData);
} }
if (!defaultValueText.isEmpty()) if (!defaultValueText.isEmpty())

View file

@ -869,10 +869,11 @@ void SplitContainer::applyFromDescriptorRecursively(
auto *node = new Node(); auto *node = new Node();
node->parent_ = baseNode; node->parent_ = baseNode;
if (const auto *n = std::get_if<ContainerNodeDescriptor>(&item)) if (const auto *inner =
std::get_if<ContainerNodeDescriptor>(&item))
{ {
node->flexH_ = n->flexH_; node->flexH_ = inner->flexH_;
node->flexV_ = n->flexV_; node->flexV_ = inner->flexV_;
} }
baseNode->children_.emplace_back(node); baseNode->children_.emplace_back(node);