From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9B5A33858C60; Thu, 7 Oct 2021 11:42:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B5A33858C60 From: "officesamurai at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBjKysvMTAyNjM3XSBOZXc6ICJFcnJvcjog4oCYcmVpbnRl?= =?UTF-8?B?cnByZXRfY2FzdOKAmSBpcyBub3QgYSBjb25zdGFudCBleHByZXNzaW9uIiB3?= =?UTF-8?B?aGVuIG5vIHJlaW50ZXJwcmV0X2Nhc3QgaXMgaW52b2x2ZWQ=?= Date: Thu, 07 Oct 2021 11:42:05 +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: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: officesamurai 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 11:42:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102637 Bug ID: 102637 Summary: "Error: =E2=80=98reinterpret_cast=E2=80=99 is not a con= stant expression" when no reinterpret_cast is involved Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: officesamurai at gmail dot com Target Milestone: --- Here I obtain a function pointer to the same member function two times, thr= ough the base and through the derived class. Then I try to compare the pointers = in a constexpr context and it fails with the error "=E2=80=98reinterpret_cast=E2= =80=99 is not a constant expression". The same happens when I try to static_cast each point= er to the opposite type. gcc_constexpr_funcptr_issue.cpp: =3D=3D=3D struct B1 { void foo(int) {} }; struct B2 { void foo(bool) {} }; struct D: B1 #ifndef ONE_BASE , B2 #endif { using B1::foo; #ifndef ONE_BASE using B2::foo; #endif }; template constexpr auto select(void (Class::*func)(Param)) { return func; } int main() { constexpr auto bFunc =3D select(&B1::foo); constexpr auto dFunc =3D select(&D::foo); static_assert(bFunc =3D=3D dFunc, ""); constexpr auto bFuncCastToDFunc =3D static_cast(bFunc= ); constexpr auto dFuncCastToBFunc =3D static_cast(dFun= c); } =3D=3D=3D Compiler invocation: =3D=3D=3D $ g++-11.2.0 -c gcc_constexpr_funcptr_issue.cpp gcc_constexpr_funcptr_issue.cpp: In function =E2=80=98int main()=E2=80=99: gcc_constexpr_funcptr_issue.cpp:33:25: error: non-constant condition for st= atic assertion 33 | static_assert(bFunc =3D=3D dFunc, ""); | ~~~~~~^~~~~~~~ gcc_constexpr_funcptr_issue.cpp:33:28: error: =E2=80=98reinterpret_cast=E2= =80=99 is not a constant expression 33 | static_assert(bFunc =3D=3D dFunc, ""); | ^~~~~ gcc_constexpr_funcptr_issue.cpp:35:39: error: =E2=80=98reinterpret_cast=E2= =80=99 is not a constant expression 35 | constexpr auto bFuncCastToDFunc =3D static_cast(bFunc); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc_constexpr_funcptr_issue.cpp:36:39: error: =E2=80=98reinterpret_cast=E2= =80=99 is not a constant expression 36 | constexpr auto dFuncCastToBFunc =3D static_cast(dFunc); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ =3D=3D=3D Additionally, if D has only one base, the call select(&D::foo) also fails: --- $ g++-11.2.0 -DONE_BASE -c gcc_constexpr_funcptr_issue.cpp gcc_constexpr_funcptr_issue.cpp: In function =E2=80=98int main()=E2=80=99: gcc_constexpr_funcptr_issue.cpp:31:42: error: =E2=80=98reinterpret_cast=E2= =80=99 is not a constant expression 31 | constexpr auto dFunc =3D select(&D::foo); | ~~~~~~~~~~~~~~^~~~~~~~~ =3D=3D=3D Finally, even if I replace the definitions of bFunc and dFunc with constexpr auto bFunc =3D &B1::foo; constexpr auto dFunc =3D &D::foo; and use -DONE_BASE, one of the casts still fails: =3D=3D=3D $ g++-11.2.0 -DONE_BASE -c gcc_constexpr_funcptr_issue.cpp gcc_constexpr_funcptr_issue.cpp: In function =E2=80=98int main()=E2=80=99: gcc_constexpr_funcptr_issue.cpp:35:39: error: =E2=80=98reinterpret_cast=E2= =80=99 is not a constant expression 35 | constexpr auto bFuncCastToDFunc =3D static_cast(bFunc); |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ =3D=3D=3D Compiler info: =3D=3D=3D $ g++-11.2.0 -v Using built-in specs. COLLECT_GCC=3Dg++-11.2.0 COLLECT_LTO_WRAPPER=3D/home/brd/soft/gcc-11.2.0/libexec/gcc/x86_64-pc-linux= -gnu/11.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --prefix=3D/home/brd/soft/gcc-11.2.0 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.0 (GCC)=20 =3D=3D=3D=