Skip to content

Commit

Permalink
Define a preprocessor flag for enabling warnings on unused Connection…
Browse files Browse the repository at this point in the history
…Handle
  • Loading branch information
phyBrackets authored and LeonMatthesKDAB committed Jun 4, 2024
1 parent 3453ba0 commit 7f948f0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/kdbindings/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

#pragma once

// Enables compiler warnings for unused ConnectionHandle results.
#ifndef KDBINDINGS_WARN_UNUSED
#define KDBINDINGS_WARN_UNUSED [[nodiscard]]
#endif

#include <assert.h>
#include <memory>
#include <stdexcept>
Expand Down Expand Up @@ -253,7 +258,7 @@ class Signal
* @return An instance of ConnectionHandle, that can be used to disconnect
* or temporarily block the connection.
*/
ConnectionHandle connect(std::function<void(Args...)> const &slot)
KDBINDINGS_WARN_UNUSED ConnectionHandle connect(std::function<void(Args...)> const &slot)
{
ensureImpl();

Expand All @@ -278,7 +283,7 @@ class Signal
* The Signal class itself is not thread-safe. While the ConnectionEvaluator is inherently
* thread-safe, ensure that any concurrent access to this Signal is protected externally to maintain thread safety.
*/
ConnectionHandle connectDeferred(const std::shared_ptr<ConnectionEvaluator> &evaluator, std::function<void(Args...)> const &slot)
KDBINDINGS_WARN_UNUSED ConnectionHandle connectDeferred(const std::shared_ptr<ConnectionEvaluator> &evaluator, std::function<void(Args...)> const &slot)
{
ensureImpl();

Expand Down

0 comments on commit 7f948f0

Please sign in to comment.