bug in g++

Dr. Andreas Klein klein@mathematik.uni-kassel.de
Fri Apr 6 02:53:00 GMT 2001


Sorry I was not able to use GNATS.

Here is my bug report:

System: Linux
GCC-version: 2.95.2

Define a template class with a corresponding friend:

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};

void f(A<int> x) {x.a++;};     

you get a warning, but the code works. Now put the whole thing in a namespace:

namespace X {

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};


void f(A<int> x) {x.a++;};    
}  

Now you get an error. f can use x.a 
(`int X::A<int>::a' is private)

If you put a function declaration befor the defintion of f
namespace X {

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};

void f(A<int> x);             
void f(A<int> x) {x.a++;};    

}  

the code works again.

if you define f ouside the namespace

namespace X {

template<typename t> class A{
    t a;
    friend void f(A<t> x);
};


}  
using namespace X;
void f(A<int> x) {x.a++;}; 

You get an Internal compiler error 378

I have no idea what is the problem.

Good bye



More information about the Gcc mailing list