https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111113
Bug ID: 111113 Summary: Cannot define friend function of a local class in namespace scope Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program defines friend function of a local class in namespace scope: auto foo() { struct A; void bar(const A&); struct A { friend void bar(const A&); }; bar(A{}); return A{}; } using A = decltype(foo()); void bar(const A&) {} Both Clang and MSVC permit it, but GCC prints weird errors: <source>:5:21: error: 'void bar(const foo()::A&)', declared using local type 'const foo()::A', is used but never defined [-fpermissive] 5 | friend void bar(const A&); | ^~~ <source>:5:21: error: 'void bar(const foo()::A&)' used but never defined <source>:12:6: warning: 'void bar(const A&)' defined but not used Online demo: https://godbolt.org/z/Yqoeda94x