Make Connect() work with overloaded event handlers in C++17
This used to work previously but got broken when using C++17 by
c3810da549
(Allow using noexcept methods with event tables macros,
2020-04-09), as cast added to deal with noexcept handlers relied on
argument type deduction which can't be done for overloaded functions.
Fix this by extracting the event argument type from the function pointer
type and specifying it explicitly, while still letting the compiler
deduce the class.
Add a test case checking that using overloaded event handlers compiles.
See #18721.
Closes #18896.
This commit is contained in:
@@ -101,6 +101,9 @@ public:
|
||||
void OnEvent(wxEvent&) { g_called.method = true; }
|
||||
void OnAnotherEvent(AnotherEvent&);
|
||||
void OnIdle(wxIdleEvent&) { g_called.method = true; }
|
||||
|
||||
void OnOverloadedHandler(wxIdleEvent&) { }
|
||||
void OnOverloadedHandler(wxThreadEvent&) { }
|
||||
};
|
||||
|
||||
// we can also handle events in classes not deriving from wxEvtHandler
|
||||
@@ -203,6 +206,14 @@ TEST_CASE("Event::LegacyConnect", "[event][connect]")
|
||||
handler.Disconnect( 0, 0, LegacyEventType, (wxObjectEventFunction)&MyHandler::OnEvent, NULL, &handler );
|
||||
}
|
||||
|
||||
TEST_CASE("Event::ConnectOverloaded", "[event][connect]")
|
||||
{
|
||||
MyHandler handler;
|
||||
|
||||
handler.Connect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnOverloadedHandler));
|
||||
handler.Connect(wxEVT_THREAD, wxThreadEventHandler(MyHandler::OnOverloadedHandler));
|
||||
}
|
||||
|
||||
TEST_CASE("Event::DisconnectWildcard", "[event][connect][disconnect]")
|
||||
{
|
||||
MyHandler handler;
|
||||
|
Reference in New Issue
Block a user