public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vbraun at physics dot upenn dot edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/30431] failure to check for visible declaration of friend function to template class Date: Wed, 25 Apr 2007 15:51:00 -0000 [thread overview] Message-ID: <20070425155130.20002.qmail@sourceware.org> (raw) In-Reply-To: <bug-30431-13734@http.gcc.gnu.org/bugzilla/> [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2113 bytes --] ------- Comment #4 from vbraun at physics dot upenn dot edu 2007-04-25 16:51 ------- Super-condensed testcase (gcc 4.1.2): -------------- snip on ----------------- template<typename T> void f() {} class A { void f() {}; friend void f<int>(); // line 5 }; -------------- snip off ----------------- [vbraun@galileo test]$ c++4 -Wall -pedantic friendtest.cc friendtest.cc:5: error: variable or field f declared void friendtest.cc:5: error: f is neither function nor member function; cannot be declared friend friendtest.cc:5: error: expected ; before < token The following versions all compile correctly (but do different things): -------------- snip on ----------------- template<typename T> void f() {} class A { void f() {}; friend void ::f<int>(); // Explicitly name scope }; ---------------------------------------- template<typename T> void f() {} class A { friend void f<int>(); // friend before member void f() {}; }; ---------------------------------------- template<typename T> void f() {} class A { void f() {}; template<typename T> friend void f(); // many-to-many friend }; ---------------------------------------- void f() {} class A { void f() {}; friend void f(); // no template }; -------------- snip off ---------------- Something is wrong with the friend lookup after a member of the same name is encountered. After seeing the class member f (either data member or member function), gcc forgets that the template function f is in the current namespace. See also: Discussion for friend lookup rules. http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#166 According to this, the code should be valid. Bug 17122 is a duplicate, but did not see any activity in 1 year. -- vbraun at physics dot upenn dot edu changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |vbraun at physics dot upenn | |dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30431
next prev parent reply other threads:[~2007-04-25 15:51 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-01-10 23:46 [Bug c++/30431] New: " tkapela at poczta dot fm 2007-01-10 23:47 ` [Bug c++/30431] " tkapela at poczta dot fm 2007-01-10 23:55 ` pinskia at gcc dot gnu dot org 2007-02-11 3:55 ` bangerth at dealii dot org 2007-04-25 15:51 ` vbraun at physics dot upenn dot edu [this message] [not found] <bug-30431-4@http.gcc.gnu.org/bugzilla/> 2012-04-12 14:56 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20070425155130.20002.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).