https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115708
Bug ID: 115708 Summary: gcc fails to identify valid friend function declaration with deduced return type Product: gcc Version: 13.2.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rush102333 at gmail dot com Target Milestone: --- Please consider the following code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct Base { auto f(int) { return 1; } }; struct A : Base { friend auto Base::f(int) ; }; int main() { A instance; auto ptr_1=&A::f; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCC-13.2 rejects this by complaining that there's no matched function for the friend declaration of "auto Base::f(int)": ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:6:17: error: no declaration matches 'auto Base::f(int)' 6 | friend auto Base::f(int) ; | ^~~~ <source>:2:10: note: candidate is: 'auto Base::f(int)' 2 | auto f(int) { return 1; } | ^ <source>:1:8: note: 'struct Base' defined here 1 | struct Base { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ That's unusual because the code is apparently valid. Changing the return type of "f" from "auto" to "int" can make the code compile. Clang also accepts this code. Please check https://godbolt.org/z/z8PYK17n8