Skip to content

Commit

Permalink
cleanup: Enable some more modernize clang-tidy checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jan 23, 2025
1 parent 0d274c0 commit 934be2b
Show file tree
Hide file tree
Showing 51 changed files with 184 additions and 179 deletions.
24 changes: 19 additions & 5 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ Checks: "-*
, google-explicit-constructor
, misc-const-correctness
, modernize-avoid-bind
, modernize-concat-nested-namespaces
, modernize-deprecated-headers
, modernize-deprecated-ios-base-aliases
, modernize-loop-convert
, -modernize-macro-to-enum
, modernize-make-shared
, modernize-make-unique
, modernize-min-max-use-initializer-list
, modernize-pass-by-value
, modernize-raw-string-literal
, modernize-redundant-void-arg
, modernize-replace-auto-ptr
, modernize-replace-disallow-copy-and-assign-macro
, modernize-replace-random-shuffle
, modernize-return-braced-init-list
, modernize-use-bool-literals
, modernize-use-emplace
, modernize-use-equals-*
, modernize-use-nullptr
, modernize-use-override
, modernize-shrink-to-fit
, modernize-type-traits
, modernize-unary-static-assert
, modernize-use-*
, -modernize-use-default-member-init
, -modernize-use-designated-initializers
, -modernize-use-nodiscard
, -modernize-use-ranges
, -modernize-use-std-numbers
, -modernize-use-trailing-return-type
, -modernize-use-using
, performance-move-const-arg
, readability-container-*
, readability-else-after-return
Expand Down
4 changes: 2 additions & 2 deletions audio/src/backend/openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ void OpenAL::cleanupOutput()
qreal OpenAL::getVolume()
{
const quint32 samples = AUDIO_FRAME_SAMPLE_COUNT_TOTAL;
const qreal rootTwo = 1.414213562; // sqrt(2), but sqrt is not constexpr
constexpr qreal sqrt2 = 1.41421356237; // std::numbers::sqrt2
// calculate volume as the root mean squared of amplitudes in the sample
qreal sumOfSquares = 0;
for (quint32 i = 0; i < samples; i++) {
Expand All @@ -629,7 +629,7 @@ qreal OpenAL::getVolume()
}
const qreal rms = std::sqrt(sumOfSquares / samples);
// our calculated normalized volume could possibly be above 1 because our RMS assumes a sinusoidal wave
const qreal normalizedVolume = std::min(rms * rootTwo, 1.0);
const qreal normalizedVolume = std::min(rms * sqrt2, 1.0);
return normalizedVolume;
}

Expand Down
4 changes: 2 additions & 2 deletions src/appmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt

bool toxURIEventHandler(const QByteArray& eventData, void* userData)
{
ToxURIDialog* uriDialog = static_cast<ToxURIDialog*>(userData);
auto* uriDialog = static_cast<ToxURIDialog*>(userData);
if (!eventData.startsWith("tox:")) {
return false;
}
Expand Down Expand Up @@ -433,7 +433,7 @@ int AppManager::run()

// If update-check is requested, do it and exit.
if (parser.isSet("update-check")) {
UpdateCheck* updateCheck = new UpdateCheck(*settings, qapp.get());
auto* updateCheck = new UpdateCheck(*settings, qapp.get());
updateCheck->checkForUpdate();
connect(updateCheck, &UpdateCheck::updateCheckFailed, qapp.get(), &QApplication::quit);
connect(updateCheck, &UpdateCheck::complete, this,
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/chatlinestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void ChatLineStorage::erase(ChatLogIdx idx)

ChatLineStorage::iterator ChatLineStorage::erase(iterator it)
{
iterator prevIt = it;
auto prevIt = it;

do {
it = prevIt;
Expand Down
6 changes: 3 additions & 3 deletions src/chatlog/chatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc
addAction(copyAction);

// Ctrl+Insert shortcut
QShortcut* copyCtrlInsShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Insert), this);
auto* copyCtrlInsShortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Insert), this);
connect(copyCtrlInsShortcut, &QShortcut::activated, this, [this]() { copySelectedText(); });

// select all action (ie. Ctrl+A)
Expand Down Expand Up @@ -1351,12 +1351,12 @@ bool ChatWidget::isActiveFileTransfer(ChatLine::Ptr l)
const int count = l->getColumnCount();
for (int i = 0; i < count; ++i) {
ChatLineContent* content = l->getContent(i);
ChatLineContentProxy* proxy = qobject_cast<ChatLineContentProxy*>(content);
auto* proxy = qobject_cast<ChatLineContentProxy*>(content);
if (proxy == nullptr)
continue;

QWidget* widget = proxy->getWidget();
FileTransferWidget* transferWidget = qobject_cast<FileTransferWidget*>(widget);
auto* transferWidget = qobject_cast<FileTransferWidget*>(widget);
if ((transferWidget != nullptr) && transferWidget->isActive())
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/conferencelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Conference* ConferenceList::addConference(Core& core, int conferenceNum,
qWarning() << "addConference: conferenceId already taken";
}

Conference* newConference = new Conference(conferenceNum, conferenceId, name, isAvConference,
selfName, core, core, friendList);
auto* newConference = new Conference(conferenceNum, conferenceId, name, isAvConference,
selfName, core, core, friendList);
conferenceList[conferenceId] = newConference;
id2key[conferenceNum] = conferenceId;
return newConference;
Expand Down
4 changes: 2 additions & 2 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Core::registerCallbacks(Tox* tox)
ToxCorePtr Core::makeToxCore(const QByteArray& savedata, const ICoreSettings& settings,
IBootstrapListGenerator& bootstrapNodes, ToxCoreErrors* err)
{
QThread* thread = new QThread();
auto* thread = new QThread();
if (thread == nullptr) {
qCritical() << "Could not allocate Core thread";
return {};
Expand Down Expand Up @@ -1179,7 +1179,7 @@ uint32_t Core::joinConference(const ConferenceInvite& inviteInfo)
const uint32_t friendId = inviteInfo.getFriendId();
const uint8_t confType = inviteInfo.getType();
const QByteArray invite = inviteInfo.getInvite();
const uint8_t* const cookie = reinterpret_cast<const uint8_t*>(invite.data());
const auto* const cookie = reinterpret_cast<const uint8_t*>(invite.data());
const size_t cookieLength = invite.length();
uint32_t conferenceNum{std::numeric_limits<uint32_t>::max()};
switch (confType) {
Expand Down
14 changes: 7 additions & 7 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ bool CoreAV::sendConferenceCallAudio(int conferenceNum, const int16_t* pcm, size
{
const QReadLocker locker{&callsLock};

const std::map<int, ToxConferenceCallPtr>::const_iterator it = conferenceCalls.find(conferenceNum);
const auto it = conferenceCalls.find(conferenceNum);
if (it == conferenceCalls.end()) {
return false;
}
Expand Down Expand Up @@ -732,7 +732,7 @@ void CoreAV::sendNoVideo()

void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool video, void* vSelf)
{
CoreAV* self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);

QWriteLocker locker{&self->callsLock};

Expand Down Expand Up @@ -771,7 +771,7 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid
void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, void* vSelf)
{
std::ignore = toxav;
CoreAV* self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);

// we must unlock this lock before emitting any signals
QWriteLocker locker{&self->callsLock};
Expand Down Expand Up @@ -830,7 +830,7 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi
void CoreAV::bitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t audioRate,
uint32_t videoRate, void* vSelf)
{
CoreAV* self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);
std::ignore = self;
std::ignore = toxav;

Expand All @@ -841,7 +841,7 @@ void CoreAV::bitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t audioRat
// This is only a dummy implementation for now
void CoreAV::audioBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rate, void* vSelf)
{
CoreAV* self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);
std::ignore = self;
std::ignore = toxav;

Expand All @@ -851,7 +851,7 @@ void CoreAV::audioBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rat
// This is only a dummy implementation for now
void CoreAV::videoBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rate, void* vSelf)
{
CoreAV* self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);
std::ignore = self;
std::ignore = toxav;

Expand All @@ -863,7 +863,7 @@ void CoreAV::audioFrameCallback(ToxAV* toxAV, uint32_t friendNum, const int16_t*
void* vSelf)
{
std::ignore = toxAV;
CoreAV* self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);
// This callback should come from the CoreAV thread
assert(QThread::currentThread() == self->coreAvThread.get());
const QReadLocker locker{&self->callsLock};
Expand Down
2 changes: 1 addition & 1 deletion src/friendlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Friend* FriendList::addFriend(uint32_t friendId, const ToxPk& friendPk, Settings
}

const QString alias = settings.getFriendAlias(friendPk);
Friend* newFriend = new Friend(friendId, friendPk, alias);
auto* newFriend = new Friend(friendId, friendPk, alias);
friendList[friendPk] = newFriend;
id2key[friendId] = friendPk;

Expand Down
2 changes: 1 addition & 1 deletion src/net/bootstrapnodeupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void jsonNodeToDhtServer(const QJsonObject& node, QList<DhtServer>& outList)
qDebug() << "Invalid port in nodes list:" << udp_port;
return;
}
const quint16 udp_port_u16 = static_cast<quint16>(udp_port);
const auto udp_port_u16 = static_cast<quint16>(udp_port);

if (!public_key.contains(ToxPkRegEx)) {
qDebug() << "Invalid public key in nodes list" << public_key;
Expand Down
8 changes: 4 additions & 4 deletions src/net/toxuri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ ToxURIDialog::ToxURIDialog(QWidget* parent, Core& core_, IMessageBoxManager& mes
userIdEdit->setCursorPosition(0);
userIdEdit->setReadOnly(true);

QLabel* userIdLabel = new QLabel(tr("User ID:"), this);
QLabel* messageLabel = new QLabel(tr("Friend request message:"), this);
auto* userIdLabel = new QLabel(tr("User ID:"), this);
auto* messageLabel = new QLabel(tr("Friend request message:"), this);
messageEdit = new QPlainTextEdit(message, this);

QDialogButtonBox* buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
auto* buttonBox = new QDialogButtonBox(Qt::Horizontal, this);

buttonBox->addButton(tr("Send", "Send a friend request"), QDialogButtonBox::AcceptRole);
buttonBox->addButton(tr("Cancel", "Don't send a friend request"), QDialogButtonBox::RejectRole);

connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);

QVBoxLayout* layout = new QVBoxLayout(this);
auto* layout = new QVBoxLayout(this);

layout->addWidget(friendsLabel);
layout->addSpacing(12);
Expand Down
4 changes: 2 additions & 2 deletions src/persistence/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Profile* Profile::loadProfile(const QString& name, const QString& password, Sett
return nullptr;
}

Profile* p = new Profile(name, std::move(tmpKey), paths, settings);
auto* p = new Profile(name, std::move(tmpKey), paths, settings);

// Core settings are saved per profile, need to load them before starting Core
constexpr bool isNewProfile = false;
Expand Down Expand Up @@ -357,7 +357,7 @@ Profile* Profile::createProfile(const QString& name, const QString& password, Se
}

Settings::createPersonal(paths, name);
Profile* p = new Profile(name, std::move(tmpKey), paths, settings);
auto* p = new Profile(name, std::move(tmpKey), paths, settings);

constexpr bool isNewProfile = true;
settings.updateProfileData(p, parser, isNewProfile);
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/profilelocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool ProfileLocker::lock(QString profile, Paths& paths)
if (lockfile && curLockName == profile)
return true;

QLockFile* newLock = new QLockFile(lockPathFromName(profile, paths));
auto* newLock = new QLockFile(lockPathFromName(profile, paths));
newLock->setStaleLockTime(0);
if (!newLock->tryLock()) {
delete newLock;
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey)
uint32_t Settings::makeProfileId(const QString& profile)
{
const QByteArray data = QCryptographicHash::hash(profile.toUtf8(), QCryptographicHash::Md5);
const uint32_t* dwords = reinterpret_cast<const uint32_t*>(data.constData());
const auto* dwords = reinterpret_cast<const uint32_t*>(data.constData());
return dwords[0] ^ dwords[1] ^ dwords[2] ^ dwords[3];
}

Expand Down
2 changes: 1 addition & 1 deletion src/persistence/settingsserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void SettingsSerializer::readIni()
}

// Clean up spurious array element groups
std::sort(std::begin(groupsToKill), std::end(groupsToKill), std::greater_equal<int>());
std::sort(std::begin(groupsToKill), std::end(groupsToKill), std::greater_equal<>());

for (const int g : groupsToKill) {
if (groupSizes[static_cast<size_t>(g)] != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const QDBusArgument& operator>>(const QDBusArgument& argument, DBusPortalImage&
// Unpack the DBus variant.
QDBusVariant variant;
argument >> variant;
const QByteArray data = variant.variant().value<QByteArray>();
const auto data = variant.variant().value<QByteArray>();
image = DBusPortalImage{QImage::fromData(data, "PNG")};
}
argument.endStructure();
Expand Down
6 changes: 2 additions & 4 deletions src/platform/x11_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

typedef struct _XDisplay Display;

namespace Platform {

namespace X11Display {
namespace Platform::X11Display {
Display* lock();
void unlock();
} // namespace X11Display
} // namespace Platform::X11Display

} // namespace Platform

#endif // QTOX_PLATFORM_EXT
2 changes: 1 addition & 1 deletion src/video/camerasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void CameraSource::setupDefault()
{
const QString deviceName_ = CameraDevice::getDefaultDeviceName(settings);
const bool isScreen = CameraDevice::isScreen(deviceName_);
VideoMode mode_ = VideoMode(settings.getScreenRegion());
auto mode_ = VideoMode(settings.getScreenRegion());
if (!isScreen) {
mode_ = VideoMode(settings.getCamVideoRes());
mode_.fps = settings.getCamVideoFPS();
Expand Down
6 changes: 3 additions & 3 deletions src/video/netcamview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_, Settings& s
buttonPanel->setStyleSheet(style.getStylesheet(BTN_STYLE_SHEET_PATH, settings));
buttonPanel->setGeometry(0, 0, BTN_PANEL_WIDTH, BTN_PANEL_HEIGHT);

QHBoxLayout* buttonPanelLayout = new QHBoxLayout(buttonPanel);
auto* buttonPanelLayout = new QHBoxLayout(buttonPanel);
buttonPanelLayout->setContentsMargins(20, 0, 20, 0);

videoPreviewButton = createButton("videoPreviewButton", "none");
Expand Down Expand Up @@ -115,7 +115,7 @@ NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_, Settings& s
selfFrame = new MovableWidget(videoSurface);
selfFrame->show();

QHBoxLayout* frameLayout = new QHBoxLayout(selfFrame);
auto* frameLayout = new QHBoxLayout(selfFrame);
frameLayout->addWidget(selfVideoSurface);
frameLayout->setContentsMargins(0, 0, 0, 0);

Expand Down Expand Up @@ -284,7 +284,7 @@ void NetCamView::toggleVideoPreview()

QPushButton* NetCamView::createButton(const QString& name, const QString& state)
{
QPushButton* btn = new QPushButton();
auto* btn = new QPushButton();
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
btn->setObjectName(name);
btn->setProperty("state", QVariant(state));
Expand Down
6 changes: 3 additions & 3 deletions src/widget/categorywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
void CategoryWidget::emitChatroomWidget(QLayout* layout, int index)
{
QWidget* widget = layout->itemAt(index)->widget();
GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
auto* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
if (chatWidget != nullptr) {
emit chatWidget->chatroomWidgetClicked(chatWidget);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ bool CategoryWidget::cycleChats(FriendWidget* activeChatroomWidget, bool forward
int index = -1;
QLayout* currentLayout = nullptr;

FriendWidget* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
auto* friendWidget = qobject_cast<FriendWidget*>(activeChatroomWidget);
if (friendWidget == nullptr)
return false;

Expand Down Expand Up @@ -225,7 +225,7 @@ bool CategoryWidget::cycleChats(FriendWidget* activeChatroomWidget, bool forward
continue;
}

GenericChatroomWidget* chatWidget =
auto* chatWidget =
qobject_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());
if (chatWidget != nullptr)
emit chatWidget->chatroomWidgetClicked(chatWidget);
Expand Down
Loading

0 comments on commit 934be2b

Please sign in to comment.