Bug 9979 - Lookup of friend function template in another namespace fails
Summary: Lookup of friend function template in another namespace fails
Status: RESOLVED DUPLICATE of bug 8355
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: ---
Assignee: Wolfgang Bangerth
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2003-03-06 09:56 UTC by nicola.musatti
Modified: 2003-06-12 00:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nicola.musatti 2003-03-06 09:56:04 UTC
A valid friend declaration of a function template from a different namespce results in the following error message:

friend.cpp:12: `void A::f(B::C*)' should have been declared inside `A'

This appears to be a known problem (it is described here: http://www.cuj.com/experts/2101/sutter.htm), but I couldn't find a specific bug report.

Release:
gcc version 3.2 (mingw special 20020817-1)

Environment:
Reading specs from d:/opt/mingw/bin/../lib/gcc-lib/mingw32/3.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.2 (mingw special 20020817-1)

How-To-Repeat:
Save the following program in file 'friend.cpp':

namespace A
{
template <typename T> void f(T * t) { delete t; } 
}

namespace B
{
class C
{
  private:
    friend void A::f<>(C *);

    ~C() {}
};
}

int main()
{
  B::C * c = new B::C;
  A::f(c);
}

Compile with g++ friend.cpp.
Comment 1 nicola.musatti 2003-03-06 09:56:04 UTC
Fix:
I tried some alternative syntaxes (e.g. by explicitly providing the friend function template argument) without success. The only workaround is to make the required members public.
Comment 2 Kriang Lerdsuwanakij 2003-03-06 14:12:19 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.
Comment 3 Wolfgang Bangerth 2003-03-06 14:20:45 UTC
*** This bug has been marked as a duplicate of 8355 ***