Skip to content

Commit

Permalink
Document that throwing within a slot is UB
Browse files Browse the repository at this point in the history
We currently don't really deal with this correctly.
Until we do so, at least mention that it's UB.
  • Loading branch information
LeonMatthesKDAB committed Jul 17, 2024
1 parent 1aec52e commit aab1cfd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/kdbindings/connection_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ConnectionEvaluator
*
* This function is responsible for evaluating and executing deferred connections.
* This function is thread safe.
*
* @warning Evaluating slots that throw an exception is currently undefined behavior.
*/
void evaluateDeferredConnections()
{
Expand Down
16 changes: 16 additions & 0 deletions src/kdbindings/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ class Signal
*
* @return An instance of ConnectionHandle, that can be used to disconnect
* or temporarily block the connection.
*
* @warning Connecting functions to a signal that throw an exception when called is currently undefined behavior.
* All connected functions should handle their own exceptions.
* For backwards-compatibility, the slot function is not required to be noexcept.
*/
KDBINDINGS_WARN_UNUSED ConnectionHandle connect(std::function<void(Args...)> const &slot)
{
Expand All @@ -346,6 +350,10 @@ class Signal
*
* @param slot A std::function that takes a ConnectionHandle reference followed by the signal's parameter types.
* @return A ConnectionHandle to the newly established connection, allowing for advanced connection management.
*
* @warning Connecting functions to a signal that throw an exception when called is currently undefined behavior.
* All connected functions should handle their own exceptions.
* For backwards-compatibility, the slot function is not required to be noexcept.
*/
ConnectionHandle connectReflective(std::function<void(ConnectionHandle &, Args...)> const &slot)
{
Expand All @@ -371,6 +379,10 @@ class Signal
* @note
* 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.
*
* @warning Connecting functions to a signal that throw an exception when called is currently undefined behavior.
* All connected functions should handle their own exceptions.
* For backwards-compatibility, the slot function is not required to be noexcept.
*/
KDBINDINGS_WARN_UNUSED ConnectionHandle connectDeferred(const std::shared_ptr<ConnectionEvaluator> &evaluator, std::function<void(Args...)> const &slot)
{
Expand Down Expand Up @@ -410,6 +422,10 @@ class Signal
* @return An instance of a Signal::ConnectionHandle that refers to this connection.
* Warning: When connecting a member function you must use the returned ConnectionHandle
* to disconnect when the object containing the slot goes out of scope!
*
* @warning Connecting functions to a signal that throw an exception when called is currently undefined behavior.
* All connected functions should handle their own exceptions.
* For backwards-compatibility, the slot function is not required to be noexcept.
**/
// The enable_if_t makes sure that this connect function specialization is only
// available if we provide a function that cannot be otherwise converted to a
Expand Down

0 comments on commit aab1cfd

Please sign in to comment.