-
Notifications
You must be signed in to change notification settings - Fork 41
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
Fix and modernize listener<> #2139
Conversation
Commit d1f50af broke the listener<> template in a subtle way: the destructor wouldn't remove listeners from the set because dynamic_cast to a derived type returns nullptr in a destructor. This caused a segfault upon saving map images. In order to solve both the warning that lead to the commit and the new bug, change the set of instances to hold listener<A>* instead of A*, and use dynamic_cast in invoke since the A objects are still valid there. While I was there, I changed invoke() to be a variadic template. It wasn't one because the code originally had to support C++03.
Backport required - or at least revert the equivalent of d1f50af in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Do we need to worry about the warning from the macOS CI?
I see these in FreeBSD too. This is nothing to worry about in my opinion. The cause is that macOS and FreeBSD use clang/LLVM as the default compiler. One could conditionalize the warning using something like this, I am not sure if it is worth it though:
|
This simplifies the user interface and removes a clang warning about it being potentially uninitialized. See longturn#2139.
Further improving the code helped removing the warning. |
This simplifies the user interface and removes a clang warning about it being potentially uninitialized. See #2139.
This simplifies the user interface and removes a clang warning about it being potentially uninitialized. See longturn#2139.
Commit d1f50af broke the listener<> template in a subtle way: the destructor wouldn't remove listeners from the set because dynamic_cast to a derived type returns nullptr in a destructor. This caused a segfault upon saving map images.
In order to solve both the warning that lead to the commit and the new bug, change the set of instances to hold listener* instead of A*, and use dynamic_cast in invoke since the A objects are still valid there.
While I was there, I changed invoke() to be a variadic template. It wasn't one because the code originally had to support C++03.