#19266: Fix for ticket 17623 (Bind doesn't work for private and protected inheritance) fails with GCC11 and std=gnu++17 mode

53 views
Skip to first unread message

wxTrac

unread,
Sep 21, 2021, 5:52:44 AM9/21/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
------------------------+-------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: GUI-all | Version: dev-latest
Keywords: gcc11 bind | Blocked By:
Blocking: | Patch: 0
------------------------+-------------------------
The fix for ticket 17623 works OK with GCC11 and std=gnu++11 or
std=gnu++14, but fails (with the same original error) when using
std=gnu++17 (default value for GCC11):

{{{
/usr/include/wx-3.1/wx/event.h:157:12: error: 'wxEvtHandler' is an
inaccessible base of 'CCManager'
}}}

where wxEvtHandler is a private base of CCManager. You can see
[https://forums.codeblocks.org/index.php/topic,24643.0.html this thread]
in the Code::Blocks forum

Using current head in C::B and wxWidgets. Reported on Arch Linux.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266>

wxTrac

unread,
Sep 24, 2021, 9:00:51 AM9/24/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------
Changes (by vadz):

* keywords: gcc11 bind => gcc11 bind C++17
* milestone: => 3.1.6


Old description:

> The fix for ticket 17623 works OK with GCC11 and std=gnu++11 or
> std=gnu++14, but fails (with the same original error) when using
> std=gnu++17 (default value for GCC11):
>
> {{{
> /usr/include/wx-3.1/wx/event.h:157:12: error: 'wxEvtHandler' is an
> inaccessible base of 'CCManager'
> }}}
>
> where wxEvtHandler is a private base of CCManager. You can see
> [https://forums.codeblocks.org/index.php/topic,24643.0.html this thread]
> in the Code::Blocks forum
>
> Using current head in C::B and wxWidgets. Reported on Arch Linux.

New description:

The fix for ticket #17623 works OK with GCC11 and std=gnu++11 or
std=gnu++14, but fails (with the same original error) when using
std=gnu++17 (default value for GCC11):

{{{
/usr/include/wx-3.1/wx/event.h:157:12: error: 'wxEvtHandler' is an
inaccessible base of 'CCManager'
}}}

where wxEvtHandler is a private base of CCManager. You can see
[https://forums.codeblocks.org/index.php/topic,24643.0.html this thread]
in the Code::Blocks forum

Using current head in C::B and wxWidgets. Reported on Arch Linux.

--

Comment:

Can the problem be reproduced just with the test code added to
`tests/events/evthandler.cpp` as part of #17623 fix or is something more
needed?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:1>

wxTrac

unread,
Sep 24, 2021, 1:12:45 PM9/24/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------

Comment (by mmarsan):

Can you tell what's the output of this code?

{{{
#include <iostream>

int main()
{
std::cout << "__cplusplus= " << __cplusplus << std::endl;
return (int)__cplusplus;
}

}}}

When executed with https://wandbox.org/ (I tried different compiler/flag
version) it gives
{{{
__cplusplus= 201703
}}}
and the 'int' return is '231'

As I side note, https://gcc.godbolt.org/ shows that {{{__cplusplus}}} is
well defined for all GCC/ICC/Clang compilers, but not for MSVC. That's why
wx code tests {{{__cplusplus}}} and MSVC version.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:2>

wxTrac

unread,
Sep 26, 2021, 3:43:51 PM9/26/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------
Changes (by mmarsan):

* cc: mmarsan@… (added)


Comment:

To add a bit of info here, I have searched the origin of the issue.
At
http://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/ccmanager.cpp:290:22
we find iside CCmanager ctor:

{{{
m_pHtml->Connect(wxEVT_COMMAND_HTML_LINK_CLICKED,
wxHtmlLinkEventHandler(CCManager::OnHtmlLink),
nullptr, this);
}}}

{{{m_pHtml}}} is a {{{wxHtmlWindow*}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:3>

wxTrac

unread,
Sep 29, 2021, 7:39:57 AM9/29/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------
Changes (by mgimenez):

* cc: webmaster@… (added)


Comment:

I cannot contact the OP from the C::B forum, i sent him a private message
and an email, but there is no response.

His problem was fixed specifying -std=gnu++14 to override the default
ghu++17

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:4>

wxTrac

unread,
Sep 29, 2021, 1:26:40 PM9/29/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------
Changes (by mmarsan):

* cc: mmarsan@… (removed)


Comment:

I don't think this ticket is related to #17623, despite of both have in
common deriving non-publicly from wxEventHander.

The issue origins at {{{wxHtmlLinkEventHandler(CCManager::OnHtmlLink)}}},
which uses the {{{wxEVENT_HANDLER_CAST( functype, func )}}} defined at
include/wx/event.h::193

A {{{static_cast<functype>(&func)}}} call is used in all C++version-
depending branches.

To me, the difference is that for ver < C++17 it uses
{{{(wxEvtHandler::*wxXXXEventFunction)(wxXXXEvent)}}} as {{{functype}}}
while for ver = C++17 it tries to cast to
{{{(wxEventHander::*)(wxXXXEvent)}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:5>

wxTrac

unread,
Sep 29, 2021, 1:30:33 PM9/29/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------

Comment (by vadz):

Sorry, I'm still not sure about the answer to the question in the
comment:1: do we have a simple way of reproducing the problem? I.e. a
simple patch to `tests/events/evthandler.cpp`?

This needs to be fixed, of course, the workaround of not using C++17 is
unacceptable, and I'll try to debug it myself, but if you already have a
way of reproducing it, please post/attach it here. TIA!

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:6>

wxTrac

unread,
Sep 29, 2021, 2:19:24 PM9/29/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------

Comment (by mmarsan):

Mmmm, add these two lines in {{{HandlerNonPublic()}}} at
tests/events/evthandler.cpp


{{{
UnBind(wxEVT_IDLE, &HandlerNonPublic::OnIdle, this);
Connect(wxEVT_IDLE, wxIdleEventHandler(HandlerNonPublic::OnIdle),nullptr,
this);

}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:7>

wxTrac

unread,
Sep 29, 2021, 2:33:17 PM9/29/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------

Comment (by vadz):

Thanks, I can indeed reproduce the problem with `g++ -std=c++17` with
`Connect()`.

But thinking more about this, we've never guaranteed that using
`Connect()` with classes not publicly-deriving from `wxEvtHandler` was
supposed to work and it takes a `wxObjectEventFunction` which is a pointer
to `wxEvtHandler` method. So I don't think this is a bug at all, after
all: you just need to use either public inheritance with `Connect()`, or
`Bind()`.

Am I missing something here or could this be simply closed, maybe after
mentioning this issue in `Connect()` documentation?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:8>

wxTrac

unread,
Sep 29, 2021, 2:46:25 PM9/29/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+------------------------------
Reporter: mgimenez | Owner:
Type: defect | Status: new
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+------------------------------

Comment (by mmarsan):

IMHO {{{Connect}}} is designed for publicly deriving from
{{{wxEventHandler}}}, ans it should be mentioined in the docs.

I still have a doubt for {{{Bind}}}. For non-publicly it continues as if
the passed {{{&C::*f}}} was a function/functor. I mean, if it loses the
'handler' info how can the per-instance binding is achieved?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:9>

wxTrac

unread,
Oct 3, 2021, 6:29:15 PM10/3/21
to wx-...@googlegroups.com
#19266: Fix for ticket 17623 (Bind doesn't work for private and protected
inheritance) fails with GCC11 and std=gnu++17 mode
-----------------------+-------------------------------------
Reporter: mgimenez | Owner: Vadim Zeitlin <vadim@…>
Type: defect | Status: closed
Priority: normal | Milestone: 3.1.6
Component: GUI-all | Version: dev-latest
Resolution: fixed | Keywords: gcc11 bind C++17
Blocked By: | Blocking:
Patch: 0 |
-----------------------+-------------------------------------
Changes (by Vadim Zeitlin <vadim@…>):

* status: new => closed
* owner: => Vadim Zeitlin <vadim@…>
* resolution: => fixed


Comment:

In [changeset:"9b5a72bd1e9f3acbef90aa3bb68facd0f6ef7bb2/git-wxWidgets"
9b5a72bd1/git-wxWidgets]:
{{{
#!CommitTicketReference repository="git-wxWidgets"
revision="9b5a72bd1e9f3acbef90aa3bb68facd0f6ef7bb2"
Document Connect() limitations compared to Bind()

Instead of just saying that Bind() is better, provide some points
illustrating why is it better.

Notable mention that Connect() can only be used with methods of the
classes publicly inheriting from wxEvtHandler, unlike Bind().

Closes #19266.
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19266#comment:10>
Reply all
Reply to author
Forward
0 new messages