Type safety of sigc::track_obj · Issue #78 · libsigcplusplus/libsigcplusplus · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Type safety of sigc::track_obj #78

Closed
@LordVolumeForm

Description

@LordVolumeForm

libsigc++ positions itself as "The Typesafe Callback Framework for C++". However, when using sigc::track_obj, there are some serious deficiencies in type safety that can all too easily lead to slots not auto-disconnecting.

The following code illustrates the problem. It contains four attempts to create an auto-disconnecting callback:

struct X : sigc::trackable {};
struct Y {};

X x;
Y y;
sigc::signal<void()> sig;

sig.connect(sigc::track_obj([] {}, x));   // good
sig.connect(sigc::track_obj([] {}, y));   // bad but compiles
sig.connect(sigc::track_obj([] {}, &x));  // bad but compiles
sig.connect(sigc::track_obj([] {}, 42));  // bad but compiles
  1. The first is the correct way. It auto-disconnects when x is destructed.
  2. Should not be allowed, as Y is not sigc::trackable, so cannot auto-disconnect.
  3. This both looks plausible and compiles, but does not auto-disconnect.
  4. Shouldn't even compile, but does so without a hitch.

This behaviour makes sigc::track_obj extremely fragile and dangerous. Code using sigc::track_obj for auto-disconnection can start silently failing when the programmer changes a type, as shown by point 2. It is also extremely easy to use incorrectly without the slightest indication something is wrong, as shown by point 3. For safety reasons, code using sigc::track_obj should only compile if auto-disconnection will actually happen. In particular, examples 2-4 should not compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.