public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/30431] failure to check for visible declaration of friend function to template class
       [not found] <bug-30431-4@http.gcc.gnu.org/bugzilla/>
@ 2012-04-12 14:56 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-12 14:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30431

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-12 14:55:08 UTC ---
(In reply to comment #4)
> 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. 

Nothing is wrong, it just finds 'f' in the class scope so doesn't look in the
enclosing namespace.  That's how name lookup works in classes.


> Bug 17122 is a duplicate, but did not see any activity in 1 year.

Yes, and like PR 17122  the code is invalid and G++ is right to reject it, but
the diagnostic could be improved.

*** This bug has been marked as a duplicate of bug 17122 ***


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/30431] failure to check for visible declaration of friend function to template class
  2007-01-10 23:46 [Bug c++/30431] New: " tkapela at poczta dot fm
                   ` (2 preceding siblings ...)
  2007-02-11  3:55 ` bangerth at dealii dot org
@ 2007-04-25 15:51 ` vbraun at physics dot upenn dot edu
  3 siblings, 0 replies; 5+ messages in thread
From: vbraun at physics dot upenn dot edu @ 2007-04-25 15:51 UTC (permalink / raw)
  To: gcc-bugs

[-- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/30431] failure to check for visible declaration of friend function to template class
  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
  3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2007-02-11  3:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bangerth at dealii dot org  2007-02-11 03:55 -------
As one data point: if it indeed finds the local function foo, then one
could think that declaring the friend as
  friend T ::foo<>(const CTest &test);
might work (note the explicit global scope on the function name). Alas:

bangerth/x> /tmp/bangerth/bin/bin/gcc -c x.cc 
x.cc:20: error: non-template 'foo' used as template
x.cc:20: note: use 'T::template foo' to indicate that it is a template
x.cc:20: error: type 'T' is not derived from type 'CTest<T>'

I must admit that I don't really know what the compiler is trying to
tell me here, it certainly doesn't make much sense...

W.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30431


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/30431] failure to check for visible declaration of friend function to template class
  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
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-01-10 23:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-01-10 23:55 -------
I think this is the correct error because it is finding class's foo.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30431


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/30431] failure to check for visible declaration of friend function to template class
  2007-01-10 23:46 [Bug c++/30431] New: " tkapela at poczta dot fm
@ 2007-01-10 23:47 ` tkapela at poczta dot fm
  2007-01-10 23:55 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: tkapela at poczta dot fm @ 2007-01-10 23:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from tkapela at poczta dot fm  2007-01-10 23:47 -------
Created an attachment (id=12883)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12883&action=view)
Simple example when compilator fails


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30431


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-12 14:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-30431-4@http.gcc.gnu.org/bugzilla/>
2012-04-12 14:56 ` [Bug c++/30431] failure to check for visible declaration of friend function to template class redi at gcc dot gnu.org
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 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).