-
Notifications
You must be signed in to change notification settings - Fork 25
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
Severe potential bug #20
Comments
signal::connect has been reworked. It now does one of the following 3: * Stores a function pointer if the callable can be converted to one * Constructs the callable in the pointer's memory via perfect forwarding * Constructs the callable on the heap via perfect forwarding One relevant test in main.cpp has been updated, and a memory leak in another test was fixed. Fixes TheWisp#20
signal::connect has been reworked. It now does one of the following 3: * Stores a function pointer if the callable can be converted to one * Constructs the callable in the pointer's memory via perfect forwarding * Constructs the callable on the heap via perfect forwarding One relevant test in main.cpp has been updated, and a memory leak in another test was fixed. Also marks conn_nontrivial destructor as an override Fixes TheWisp#20
Thank you for bringing up the topic, it is actually a more complex design problem than it seems. I would like more feedback from you! |
I have added this compile-time assert to connect() to be on the safe side and keep best performances: static_assert(! std::is_lvalue_reference::value, "Use std::move() or construct{} the functor at call's location"); |
Sorry, I would have commented earlier, but I just noticed the activity here. I would argue that silently storing references is usually nonintuitive behavior and that copying lvalues is more idiomatic (e.g., If lvalues are copied, then given the example in #9, I think Furthermore, the existing behavior means that callables that are both movable and copyable can never be copied into Just my two cents :) |
Isn't this fixed already? I've skimmed latest commits and it seems addressed there. |
I do not believe this has been fixed, but you can try my pull request above (#21). The last commit I see was a year ago -- where did you see it was fixed? |
My bad - I've read the commit comment incorrectly and now I've looked at the code and it seems unrelated. |
Run the following code: the assert will fail.
This is simply because the lambda is not copied to 'sig',
hence its data destructed before sig(10); is reached.
By using std::move(lambda), the problem is solved.
But it's easy to forget this and have this bug during run time.
The text was updated successfully, but these errors were encountered: