-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type safety of sigc::track_obj #78
Comments
Yes, sigc::track_obj() can (and should) be improved. static_assert() can probably Adding restrictions to sigc::track_obj() would break API, though. Code that has Even with a static_assert(), sigc::track_obj() would not be completely safe. |
A compile-time warning would be fine for now. Maybe instead of |
track_object() checks that the listed objects derive from sigc::trackable. Fixes #78
libsigc++
positions itself as "The Typesafe Callback Framework for C++". However, when usingsigc::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:
x
is destructed.Y
is notsigc::trackable
, so cannot auto-disconnect.This behaviour makes
sigc::track_obj
extremely fragile and dangerous. Code usingsigc::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 usingsigc::track_obj
should only compile if auto-disconnection will actually happen. In particular, examples 2-4 should not compile.The text was updated successfully, but these errors were encountered: