public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope @ 2023-08-23 9:16 fchelnokov at gmail dot com 2023-08-23 17:59 ` [Bug c++/111113] " pinskia at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: fchelnokov at gmail dot com @ 2023-08-23 9:16 UTC (permalink / raw) To: gcc-bugs 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/111113] Cannot define friend function of a local class in namespace scope 2023-08-23 9:16 [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope fchelnokov at gmail dot com @ 2023-08-23 17:59 ` pinskia at gcc dot gnu.org 2023-08-23 18:05 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-23 17:59 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111113 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2023-08-23 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. Another testcase which might show what is really going on: ``` 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&) {} int main() { bar(foo()); } ``` We get the following error message: ``` <source>: In function 'int main()': <source>:16:12: error: call of overloaded 'bar(foo()::A)' is ambiguous 16 | bar(foo()); | ~~~^~~~~~~ <source>:12:6: note: candidate: 'void bar(const A&)' 12 | void bar(const A&) {} | ^~~ <source>:5:21: note: candidate: 'void bar(const foo()::A&)' 5 | friend void bar(const A&); | ^~~ ``` Which is not correct as bar in this case is the same bar. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/111113] Cannot define friend function of a local class in namespace scope 2023-08-23 9:16 [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope fchelnokov at gmail dot com 2023-08-23 17:59 ` [Bug c++/111113] " pinskia at gcc dot gnu.org @ 2023-08-23 18:05 ` pinskia at gcc dot gnu.org 2023-08-23 18:10 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-23 18:05 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111113 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=51757 Known to fail| |4.8.1 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #1) > Confirmed. > > Another testcase which might show what is really going on: ... > Which is not correct as bar in this case is the same bar. The ambiguous error message was added in GCC 11. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/111113] Cannot define friend function of a local class in namespace scope 2023-08-23 9:16 [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope fchelnokov at gmail dot com 2023-08-23 17:59 ` [Bug c++/111113] " pinskia at gcc dot gnu.org 2023-08-23 18:05 ` pinskia at gcc dot gnu.org @ 2023-08-23 18:10 ` pinskia at gcc dot gnu.org 2023-08-23 18:16 ` pinskia at gcc dot gnu.org 2023-08-23 23:30 ` language.lawyer at gmail dot com 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-23 18:10 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111113 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=101356 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I think this is a dup of bug 101356. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/111113] Cannot define friend function of a local class in namespace scope 2023-08-23 9:16 [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope fchelnokov at gmail dot com ` (2 preceding siblings ...) 2023-08-23 18:10 ` pinskia at gcc dot gnu.org @ 2023-08-23 18:16 ` pinskia at gcc dot gnu.org 2023-08-23 23:30 ` language.lawyer at gmail dot com 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-23 18:16 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111113 --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #3) > I think this is a dup of bug 101356. Well at least it is a related issue; maybe not a dup. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/111113] Cannot define friend function of a local class in namespace scope 2023-08-23 9:16 [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope fchelnokov at gmail dot com ` (3 preceding siblings ...) 2023-08-23 18:16 ` pinskia at gcc dot gnu.org @ 2023-08-23 23:30 ` language.lawyer at gmail dot com 4 siblings, 0 replies; 6+ messages in thread From: language.lawyer at gmail dot com @ 2023-08-23 23:30 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111113 Language Lawyer <language.lawyer at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |language.lawyer at gmail dot com --- Comment #5 from Language Lawyer <language.lawyer at gmail dot com> --- (In reply to Andrew Pinski from comment #3) > I think this is a dup of bug 101356. Looks dup to me too. Looks like GCC does not match friend function declaration with its namespace declaration. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-08-23 23:30 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-08-23 9:16 [Bug c++/111113] New: Cannot define friend function of a local class in namespace scope fchelnokov at gmail dot com 2023-08-23 17:59 ` [Bug c++/111113] " pinskia at gcc dot gnu.org 2023-08-23 18:05 ` pinskia at gcc dot gnu.org 2023-08-23 18:10 ` pinskia at gcc dot gnu.org 2023-08-23 18:16 ` pinskia at gcc dot gnu.org 2023-08-23 23:30 ` language.lawyer at gmail dot com
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).