From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B47473858C27; Fri, 22 Sep 2023 00:30:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B47473858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695342623; bh=ZoLaX0BuLya1yeQbOCmM3Y5Ngu7O+GL7S4DQlmmUNfw=; h=From:To:Subject:Date:From; b=RAaIzP03tIKUE3vZSwgqbujmfOnk3GINZzbgoxvj4+g6Ypxh0L4OcSmUnWB3lBKbs oSmHoOIaalGPBea/b2nuphof5Yw5XkTU7JPTI2grMcza6qMb4VuIrtj+RsfgT7xzkz 1DcEbc9EAolcX04ZPLdSHjHmKzKKhzPZBhc7PvEA= From: "paulhaile3 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111531] New: Bound member function (-Wno-pmf-conversions) with multiple inheritance Date: Fri, 22 Sep 2023 00:30:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: paulhaile3 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111531 Bug ID: 111531 Summary: Bound member function (-Wno-pmf-conversions) with multiple inheritance Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: paulhaile3 at gmail dot com Target Milestone: --- I noticed a bug with bound pointer to member functions that I would like to report. When using multiple inheritance, the this pointer is incorrect and results in undefined behavior. See the example below, which is modified from https://github.com/llvm/llvm-project/issues/22495. The last set of addresses are incorrect - e.g. this resolves to the address of struct B, instead of A, which means accessing the data member this->x is undefined. """ #include struct A { int x; void f() {=20 printf("A-in-B [A::f]: %p\n", this); printf("address of x: %p, value of x: %d\n", &this->x, this->x); } }; struct X { char y; }; struct B : X, A {}; typedef void (B::*b_mp)(); typedef void (*b_fptr)(B *); int main() { B b; b.x =3D 100; b_mp mp =3D &A::f; printf("B: [main]: %p\n", &b); printf("address of x: %p, value of x: %d\n", &b.x, b.x); printf("A-in-B [main]: %p\n", (A *)&b); (b.*mp)(); b_fptr fp =3D (b_fptr)(&A::f); fp(&b); } """ Output: B: [main]: 0x7fff4772e958 address of x: 0x7fff4772e95c, value of x: 100 A-in-B [main]: 0x7fff4772e95c A-in-B [A::f]: 0x7fff4772e95c address of x: 0x7fff4772e95c, value of x: 100 A-in-B [A::f]: 0x7fff4772e958 address of x: 0x7fff4772e958, value of x: 0 Compiled with x86-64 gcc 13.2 with flags "-O3 --std=3Dc++20 -Wno-pmf-conver= sions"=