[Bug c++/30431] failure to check for visible declaration of friend function to template class

2012-04-12 Thread redi at gcc dot gnu.org
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 ***


[Bug c++/30431] failure to check for visible declaration of friend function to template class

2007-04-25 Thread vbraun at physics dot upenn dot edu


--- Comment #4 from vbraun at physics dot upenn dot edu  2007-04-25 16:51 
---
Super-condensed testcase (gcc 4.1.2):

-- snip on -
templatetypename T void f() {}
class A
{
  void f() {};
  friend void fint();   // line 5
};
-- snip off -

[EMAIL PROTECTED] 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 -
templatetypename T void f() {}
class A
{
  void f() {};
  friend void ::fint();   // Explicitly name scope
};

templatetypename T void f() {}
class A
{
  friend void fint();   // friend before member
  void f() {};
};

templatetypename T void f() {}
class A
{
  void f() {};
  templatetypename 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



[Bug c++/30431] failure to check for visible declaration of friend function to template class

2007-02-10 Thread bangerth at dealii dot org


--- 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 'CTestT'

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



[Bug c++/30431] failure to check for visible declaration of friend function to template class

2007-01-10 Thread tkapela at poczta dot fm


--- 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=12883action=view)
Simple example when compilator fails


-- 


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



[Bug c++/30431] failure to check for visible declaration of friend function to template class

2007-01-10 Thread pinskia at gcc dot gnu dot org


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