Skip to content

Commit

Permalink
Fix [[nodiscard]] warnings coming from KDBindings
Browse files Browse the repository at this point in the history
std::ignore used in cases where we don't need to store the connection.
I think it's more descriptive than (void).

Technically, using std::ignore is UB until Peppe's P2968 is ratified in
C++26 but every implementation we target does the right thing so I don't
care. Sue me.
  • Loading branch information
MiKom committed Jul 16, 2024
1 parent 9d84069 commit af58123
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/gui_window/gui_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main()
w.title = "KDGui window example";
w.visible = true;

w.visible.valueChanged().connect([&app](bool visible) {
KDBindings::ScopedConnection conn = w.visible.valueChanged().connect([&app](bool visible) {
if (!visible) {
app.quit();
}
Expand Down
6 changes: 3 additions & 3 deletions src/KDFoundation/platform/linux/linux_platform_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ using namespace KDFoundation;
LinuxPlatformTimer::LinuxPlatformTimer(Timer *timer)
: m_notifier(timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC), FileDescriptorNotifier::NotificationType::Read)
{
m_notifier.triggered.connect([this, timer]() {
m_notifierConnection = m_notifier.triggered.connect([this, timer]() {
char buf[8];
const auto bytes = read(m_notifier.fileDescriptor(), buf, 8);
KD_UNUSED(bytes);
timer->timeout.emit();
});

timer->running.valueChanged().connect([this, timer](bool running) {
m_timerRunningConnection = timer->running.valueChanged().connect([this, timer](bool running) {
if (running) {
arm(timer->interval.get());
} else {
disarm();
}
});
timer->interval.valueChanged().connect([this, timer]() {
m_timerIntervalConnection = timer->interval.valueChanged().connect([this, timer]() {
if (timer->running.get()) {
arm(timer->interval.get());
}
Expand Down
5 changes: 5 additions & 0 deletions src/KDFoundation/platform/linux/linux_platform_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <chrono>

#include <kdbindings/signal.h>

#include <KDFoundation/platform/abstract_platform_timer.h>
#include <KDFoundation/file_descriptor_notifier.h>

Expand All @@ -35,6 +37,9 @@ class KDFOUNDATION_API LinuxPlatformTimer : public AbstractPlatformTimer
int fd;
} m_fdCloser;
FileDescriptorNotifier m_notifier;
KDBindings::ScopedConnection m_notifierConnection;
KDBindings::ScopedConnection m_timerRunningConnection;
KDBindings::ScopedConnection m_timerIntervalConnection;
};

} // namespace KDFoundation
4 changes: 2 additions & 2 deletions src/KDFoundation/platform/win32/win32_platform_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ inline Win32PlatformEventLoop *eventLoop()
Win32PlatformTimer::Win32PlatformTimer(Timer *timer)
: m_timer(timer)
{
timer->running.valueChanged().connect([this, timer](bool running) {
m_timerRunningConnection = timer->running.valueChanged().connect([this, timer](bool running) {
if (running) {
arm(timer->interval.get());
} else {
disarm();
}
});
timer->interval.valueChanged().connect([this, timer]() {
m_timerIntervalConnection = timer->interval.valueChanged().connect([this, timer]() {
if (timer->running.get()) {
arm(timer->interval.get());
}
Expand Down
3 changes: 3 additions & 0 deletions src/KDFoundation/platform/win32/win32_platform_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <chrono>
#include <windows.h>
#include <kdbindings/signal.h>
#undef max

#include <KDFoundation/platform/abstract_platform_timer.h>
Expand All @@ -33,6 +34,8 @@ class KDFOUNDATION_API Win32PlatformTimer : public AbstractPlatformTimer
static void callback(HWND hwnd, UINT uMsg, UINT_PTR timerId, DWORD dwTime);

Timer *m_timer;
KDBindings::ScopedConnection m_timerRunningConnection;
KDBindings::ScopedConnection m_timerIntervalConnection;
uintptr_t m_id{ 0 };
};

Expand Down
2 changes: 1 addition & 1 deletion src/KDGui/abstract_platform_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AbstractPlatformWindow::AbstractPlatformWindow(Window *window, AbstractPlatformW
, m_type(type)
{
assert(window);
window->title.valueChanged().connect(&AbstractPlatformWindow::setTitle, this);
m_titleChangedConnection = window->title.valueChanged().connect(&AbstractPlatformWindow::setTitle, this);
}

AbstractPlatformWindow::Type AbstractPlatformWindow::type() const
Expand Down
3 changes: 3 additions & 0 deletions src/KDGui/abstract_platform_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <KDGui/kdgui_keys.h>
#include <KDGui/gui_events.h>

#include <kdbindings/signal.h>

#include <string>

namespace KDGui {
Expand Down Expand Up @@ -86,6 +88,7 @@ class KDGUI_API AbstractPlatformWindow

protected:
Window *m_window;
KDBindings::ScopedConnection m_titleChangedConnection;
AbstractPlatformWindow::Type m_type;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <wayland-zwp-relative-pointer-unstable-v1-client-protocol.h>
#include <wayland-zwp-pointer-constraints-v1-client-protocol.h>

#include <tuple>

using namespace KDGui;

LinuxWaylandPlatformInput::LinuxWaylandPlatformInput(LinuxWaylandPlatformIntegration *integration,
Expand All @@ -41,7 +43,7 @@ LinuxWaylandPlatformInput::LinuxWaylandPlatformInput(LinuxWaylandPlatformIntegra
};
wl_seat_add_listener(seat, &listener, this);

m_keyboard.repeat.timer.timeout.connect(&LinuxWaylandPlatformInput::keyboardRepeatKey, this);
std::ignore = m_keyboard.repeat.timer.timeout.connect(&LinuxWaylandPlatformInput::keyboardRepeatKey, this);
}

LinuxWaylandPlatformInput::~LinuxWaylandPlatformInput()
Expand Down Expand Up @@ -223,7 +225,7 @@ void LinuxWaylandPlatformInput::pointerEnter(wl_pointer *pointer, uint32_t seria
m_pointer.accumulatedEvent.focusChange = true;
} else {
m_pointer.focus = LinuxWaylandPlatformWindow::fromSurface(surface);
m_pointer.focus->cursorChanged.connect(&LinuxWaylandPlatformInput::setCursor, this);
std::ignore = m_pointer.focus->cursorChanged.connect(&LinuxWaylandPlatformInput::setCursor, this);
setCursor();
}
}
Expand Down Expand Up @@ -333,7 +335,7 @@ void LinuxWaylandPlatformInput::pointerFrame(wl_pointer *pointer)
auto &ev = m_pointer.accumulatedEvent;
if (ev.focusChange && ev.focus) {
m_pointer.focus = ev.focus;
m_pointer.focus->cursorChanged.connect(&LinuxWaylandPlatformInput::setCursor, this);
std::ignore = m_pointer.focus->cursorChanged.connect(&LinuxWaylandPlatformInput::setCursor, this);
setCursor();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <array>
#include <cassert>
#include <tuple>

using namespace KDFoundation;
using namespace KDGui;
Expand All @@ -34,12 +35,12 @@ LinuxWaylandPlatformWindow::LinuxWaylandPlatformWindow(
: AbstractPlatformWindow(window, AbstractPlatformWindow::Type::Wayland)
, m_platformIntegration{ platformIntegration }
{
CoreApplication::instance()->applicationName.valueChanged().connect([this]() {
std::ignore = CoreApplication::instance()->applicationName.valueChanged().connect([this]() {
if (m_toplevel) {
setAppId();
}
});
window->scaleFactor.valueChanged().connect([this](float value) {
m_scaleChangedConnection = window->scaleFactor.valueChanged().connect([this](float value) {
if (m_surface) {
wl_surface_set_buffer_scale(m_surface, int32_t(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class KDGUI_API LinuxWaylandPlatformWindow : public AbstractPlatformWindow
CursorMode m_cursorMode{ CursorMode::Normal };
MouseButtons m_mouseButtons{ MouseButton::NoButton };
std::vector<LinuxWaylandPlatformOutput *> m_enteredOutputs;
KDBindings::ScopedConnection m_scaleChangedConnection;
};

} // namespace KDGui
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <xcb/xcb.h>

#include <tuple>

using namespace KDFoundation;
using namespace KDGui;

Expand All @@ -39,7 +41,7 @@ LinuxXcbPlatformEventLoop::LinuxXcbPlatformEventLoop(LinuxXcbPlatformIntegration
auto xcbfd = xcb_get_file_descriptor(connection);
SPDLOG_LOGGER_DEBUG(m_logger, "Registering xcb fd {} with event loop", xcbfd);
m_xcbNotifier = std::make_unique<FileDescriptorNotifier>(xcbfd, FileDescriptorNotifier::NotificationType::Read);
m_xcbNotifier->triggered.connect([this](const int &) {
std::ignore = m_xcbNotifier->triggered.connect([this](const int &) {
this->m_xcbEventsPending = true;
});

Expand Down
8 changes: 5 additions & 3 deletions src/KDGui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <KDFoundation/platform/abstract_platform_integration.h>
#include <KDFoundation/event.h>

#include <tuple>

using namespace KDFoundation;
using namespace KDGui;

Expand All @@ -24,13 +26,13 @@ Window::Window()
, m_logger{ KDUtils::Logger::logger("window", spdlog::level::info) }
{

visible.valueChanged().connect(&Window::onVisibleChanged, this);
std::ignore = visible.valueChanged().connect(&Window::onVisibleChanged, this);
m_resizeConnectionIds = {
width.valueChanged().connect(&Window::onSizeChanged, this),
height.valueChanged().connect(&Window::onSizeChanged, this)
};
cursorEnabled.valueChanged().connect(&Window::onCursorEnabledChanged, this);
rawMouseInputEnabled.valueChanged().connect(&Window::onRawMouseInputEnabledChanged, this);
std::ignore = cursorEnabled.valueChanged().connect(&Window::onCursorEnabledChanged, this);
std::ignore = rawMouseInputEnabled.valueChanged().connect(&Window::onRawMouseInputEnabledChanged, this);
}

Window::~Window()
Expand Down
3 changes: 2 additions & 1 deletion tests/auto/foundation/common/signal_spy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SignalSpy
template<typename Signal>
explicit SignalSpy(Signal &s)
{
s.connect([this](Args... args) {
m_connection = s.connect([this](Args... args) {
callback(args...);
});
}
Expand Down Expand Up @@ -74,4 +74,5 @@ class SignalSpy

uint32_t m_count = 0;
std::tuple<Args...> m_args;
KDBindings::ScopedConnection m_connection;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <condition_variable>
#include <mutex>
#include <thread>
#include <tuple>

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
Expand Down Expand Up @@ -203,7 +204,7 @@ TEST_CASE("Timer handling")
int timeout = 0;
auto startTime = std::chrono::steady_clock::now();
auto time = startTime;
timer.timeout.connect([&]() {
std::ignore = timer.timeout.connect([&]() {
const auto endTime = std::chrono::steady_clock::now();
REQUIRE(endTime - time > 50ms);
REQUIRE(endTime - time < 150ms);
Expand Down Expand Up @@ -240,7 +241,7 @@ TEST_CASE("Timer handling")

bool fired = false;

timer.timeout.connect([&] {
std::ignore = timer.timeout.connect([&] {
fired = true;
});

Expand Down
3 changes: 2 additions & 1 deletion tests/auto/foundation/object/tst_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <numeric>
#include <string>
#include <tuple>

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest.h>
Expand Down Expand Up @@ -288,7 +289,7 @@ TEST_CASE("Object destruction")

for (int i = 0; i < 10; ++i) {
auto child = parent->createChild<IntObject>(i);
child->aboutToBeDestroyed.connect(onAboutToBeDestroyed);
std::ignore = child->aboutToBeDestroyed.connect(onAboutToBeDestroyed);
}
// THEN
REQUIRE(childRemovedSpy.count() == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <numeric>
#include <string>
#include <thread>
#include <tuple>

#include <WinSock2.h>
#include <WS2tcpip.h>
Expand Down Expand Up @@ -185,15 +186,15 @@ TEST_CASE("Wait for events")
// A notifier for testing deregistration
int unregisteredCalls = 0;
FileDescriptorNotifier unregistered(clientSock, FileDescriptorNotifier::NotificationType::Read);
unregistered.triggered.connect([&unregisteredCalls] {
std::ignore = unregistered.triggered.connect([&unregisteredCalls] {
unregisteredCalls++;
});
loop.registerNotifier(&unregistered);
loop.unregisterNotifier(&unregistered);

// Set up read notifier to receive the data
FileDescriptorNotifier readNotifier(clientSock, FileDescriptorNotifier::NotificationType::Read);
readNotifier.triggered.connect([&dataReceived](int fd) {
std::ignore = readNotifier.triggered.connect([&dataReceived](int fd) {
char buf[128] = {};
recv(fd, buf, 128, 0);
const int recvSize = recv(fd, buf, 128, 0);
Expand All @@ -205,7 +206,7 @@ TEST_CASE("Wait for events")
// A notifier for testing Write notification type
FileDescriptorNotifier writeNotifier(clientSock, FileDescriptorNotifier::NotificationType::Write);
int writeTriggered = 0;
writeNotifier.triggered.connect([&writeTriggered]() {
std::ignore = writeNotifier.triggered.connect([&writeTriggered]() {
writeTriggered++;
});
loop.registerNotifier(&writeNotifier);
Expand Down
9 changes: 5 additions & 4 deletions tests/auto/utils/signal/tst_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <kdbindings/signal.h>

#include <thread>
#include <tuple>

using namespace KDUtils;

Expand All @@ -31,13 +32,13 @@ TEST_SUITE("Signal")
KDBindings::Signal<int> signal2;

std::thread thread1([&] {
signal1.connectDeferred(app.connectionEvaluator(), [&val](int value) {
std::ignore = signal1.connectDeferred(app.connectionEvaluator(), [&val](int value) {
val += value;
});
});

std::thread thread2([&] {
signal2.connectDeferred(app.connectionEvaluator(), [&val](int value) {
std::ignore = signal2.connectDeferred(app.connectionEvaluator(), [&val](int value) {
val += value;
});
});
Expand Down Expand Up @@ -91,11 +92,11 @@ TEST_SUITE("Signal")
int val1 = 4;
int val2 = 4;

signal1.connectDeferred(app.connectionEvaluator(), [&val1](int value) {
std::ignore = signal1.connectDeferred(app.connectionEvaluator(), [&val1](int value) {
val1 += value;
});

signal2.connectDeferred(app.connectionEvaluator(), [&val2](int value) {
std::ignore = signal2.connectDeferred(app.connectionEvaluator(), [&val2](int value) {
val2 += value;
});

Expand Down

0 comments on commit af58123

Please sign in to comment.