[Bug c++/126639] New: Undiagnosed undefined behaviour in pointer-to-member conversion

"ivan.lazaric.gcc at gmail dot com via Gcc-bugs" <[email protected]> Tue, 04 Aug 2026 13:17:41 +0000
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D126639

            Bug ID: 126639
           Summary: Undiagnosed undefined behaviour in pointer-to-member
                    conversion
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ivan.lazaric.gcc at gmail dot com
  Target Milestone: ---

```cpp
struct A { char a; };
struct B { char b; };
struct AB : A, B {};

constexpr auto ap =3D &A::a;
constexpr auto abp =3D (char AB::*)ap;
constexpr auto bp =3D (char B::*)abp; // this is UB

static_assert(bp =3D=3D nullptr);
```

This code compiles, because after pointer-to-member conversion
gcc only tracks the offset, the offset in bp becomes -1,
which coincides with nullptr representation in ptr-to-members.

https://eel.is/c++draft/conv.mem#2
> If class D does not contain the original member and is not a base class o=
f the class containing the original member, the behavior is undefined

clang diagnoses this

Godbolt: https://godbolt.org/z/64hfcjKq6=