From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 067EB3858404; Thu, 8 Sep 2022 21:53:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 067EB3858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662673982; bh=u/q4V4Z5s47oqtpdhy69lkQkWmhFeVXr3VMKC+0NXEc=; h=From:To:Subject:Date:From; b=dom9eqD+ttDZAWDXV4U7dRwpxxVZgJ/edGRqel0Sxwevs1v9iq9pnK73xWYOPGvZn An/pqHDSNLBR8r9jXhSYvF+pu0NnGuJKWzDkPz/hQcVn14jpSu681+Jo8lVhyROuZA Bxt8GVw+2kqSAkfqcFW3hYwqKrqXz97RQtdw5cbc= From: "dan at stahlke dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106893] New: auto deduces wrong type for function pointer Date: Thu, 08 Sep 2022 21:53:01 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dan at stahlke dot org 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=3D106893 Bug ID: 106893 Summary: auto deduces wrong type for function pointer Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dan at stahlke dot org Target Milestone: --- This works in 11.3.0 but not in 12.2.0. struct IntegerCoordinate { int x() const; int y() const; }; template struct CoordTraits { static auto GetX(T const &p) { return p.x(); } static auto GetY(T const &p) { return p.y(); } using Ordinate =3D decltype(GetX(T{})); }; template struct Node { static constexpr auto GetX =3D Traits::GetX; // works because of the `u= sing Ordinate =3D ...` static constexpr auto GetY =3D Traits::GetY; // compilation error // This compiles //static constexpr auto GetX =3D &Traits::GetX; //static constexpr auto GetY =3D &Traits::GetY; // This compiles //using fptr =3D int(*)(IntegerCoordinate const &); //static constexpr fptr GetX =3D Traits::GetX; //static constexpr fptr GetY =3D Traits::GetY; // Not needed for minimal test case auto x(auto const &p) const { return GetX(p); } auto y(auto const &p) const { return GetY(p); } }; int main() { Node> node; // Not needed for minimal test case node.x(IntegerCoordinate{}); node.y(IntegerCoordinate{}); } $ g++ -std=3Dc++20 gcc-function-ptr-bug.cpp -c -o gcc-function-ptr-bug.o gcc-function-ptr-bug.cpp: In instantiation of =E2=80=98constexpr auto (* co= nst Node >::GetY)(const IntegerCoordinate&)=E2= =80=99: gcc-function-ptr-bug.cpp:17:27: required from =E2=80=98struct Node >=E2=80=99 gcc-function-ptr-bug.cpp:32:42: required from here gcc-function-ptr-bug.cpp:17:27: error: invalid conversion from =E2=80=98int= (*)(const IntegerCoordinate&)=E2=80=99 to =E2=80=98auto (*)(const IntegerCoordinate&)= =E2=80=99 [-fpermissive] 17 | static constexpr auto GetY =3D Traits::GetY; // compilation err= or | ^~~~ | | | int (*)(const IntegerCoordinate&) gcc-function-ptr-bug.cpp: In instantiation of =E2=80=98auto Node::y= (const auto:2&) const [with auto:2 =3D IntegerCoordinate; Traits =3D CoordTraits]=E2=80=99: gcc-function-ptr-bug.cpp:35:11: required from here gcc-function-ptr-bug.cpp:28:46: error: use of =E2=80=98Node >::GetY=E2=80=99 before deduct= ion of =E2=80=98auto=E2=80=99 28 | auto y(auto const &p) const { return GetY(p); } | ~~~~^~~=